Skip to content

Commit

Permalink
Merge pull request #234 from kommitters/v2.0
Browse files Browse the repository at this point in the history
Release v2.0.24
  • Loading branch information
MarioRodriguezS authored Oct 17, 2023
2 parents d73dd46 + ae70e2d commit 3536d4c
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 17 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ on:
- 'v*.[0-9]'
pull_request:

permissions: # added using https://github.com/step-security/secure-workflows
permissions: # added using https://github.com/step-security/secure-workflows
contents: read

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@03bee3930647ebbf994244c21ddbc0d4933aab4f # v2.3.0
uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.1
with:
disable-sudo: true
egress-policy: block
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ jobs:

steps:
- name: Harden Runner
uses: step-security/harden-runner@03bee3930647ebbf994244c21ddbc0d4933aab4f # v2.3.0
uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.1
with:
disable-sudo: true
egress-policy: block
allowed-endpoints: >
api.github.com:443
*.github.com:443
github.com:443
objects.githubusercontent.com:443
*.githubapp.com:443
*.githubusercontent.com:443
- name: Checkout repository
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@03bee3930647ebbf994244c21ddbc0d4933aab4f # v2.3.0
uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.1
with:
disable-sudo: true
egress-policy: block
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:

steps:
- name: Harden Runner
uses: step-security/harden-runner@03bee3930647ebbf994244c21ddbc0d4933aab4f # v2.3.0
uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.1
with:
disable-sudo: true
egress-policy: block
Expand All @@ -34,7 +34,8 @@ jobs:
fulcio.sigstore.dev:443
github.com:443
rekor.sigstore.dev:443
sigstore-tuf-root.storage.googleapis.com:443
bestpractices.dev:443
*.storage.googleapis.com:443
- name: "Checkout code"
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.0.24 (17.10.2023)

- Fix bug [#227](https://github.com/kommitters/editorjs-undo/issues/227) - Fix unexpected behavior when there are line breaks.
- Fix bug [#202](https://github.com/kommitters/editorjs-undo/issues/202) - Solve undo with custom blocks.
- Update [#225](https://github.com/kommitters/editorjs-undo/pull/225) - Update codeql.yml and scorecards.yml allowed-endpoints.

## 2.0.23 (15.09.2023)

- Fix bug [#213](https://github.com/kommitters/editorjs-undo/issues/213) - Add support to different keyboard distributions.
Expand Down
2 changes: 1 addition & 1 deletion dist/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "editorjs-undo",
"version": "2.0.23",
"version": "2.0.24",
"keywords": [
"undo",
"redo",
Expand Down
11 changes: 6 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class Undo {

const { blocks, caret } = editor;
const { configuration } = editor;
const { holder } = configuration;
const { holder, defaultBlock } = configuration;
const defaultShortcuts = defaultOptions.config.shortcuts;
const { shortcuts: configShortcuts } = config;
const shortcuts = { ...defaultShortcuts, ...configShortcuts };
Expand All @@ -43,6 +43,7 @@ export default class Undo {
this.holder =
typeof holder === "string" ? document.getElementById(holder) : holder;
this.editor = editor;
this.defaultBlock = defaultBlock;
this.blocks = blocks;
this.caret = caret;
this.shouldSaveHistory = true;
Expand Down Expand Up @@ -104,7 +105,7 @@ export default class Undo {
clear() {
this.stack = this.initialItem
? [this.initialItem]
: [{ index: 0, state: [{ type: "paragraph", data: { text: "" } }] }];
: [{ index: 0, state: [{ type: this.defaultBlock, data: {} }] }];
this.position = 0;
this.onUpdate();
}
Expand Down Expand Up @@ -271,14 +272,14 @@ export default class Undo {
if (this.blockWasDeleted(state, nextState)) {
this.insertDeletedBlock(state, nextState, index);
} else if (this.blockWasSkipped(index, nextIndex, state, nextState)) {
this.blocks.delete();
this.blocks.delete(nextIndex);
this.caret.setToBlock(index, "end");
} else if (blockCount > state.length) {
this.blocks
.render({ blocks: state })
.then(() => {
this.editor.blocks.insert("paragraph", {text: ""})
this.caret.setToLastBlock("end") ;
this.editor.blocks.insert(this.defaultBlock, {});
this.setCaretIndex(index, caretIndex);
});
} else if (this.blockWasDropped(state, nextState)) {
this.blocks
Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const editor = {
caret: {
setToBlock() {},
},
configuration: {},
configuration: {
defaultBlock: 'paragraph',
},
};

const readOnlyEditor = {
Expand Down
2 changes: 1 addition & 1 deletion test/undo.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('Undo', () => {
undo = new Undo({ editor });
});

const intialStackData = { index: 0, state: [{ type: 'paragraph', data: { text: '' } }] };
const intialStackData = { index: 0, state: [{ type: 'paragraph', data: {} }] };

it('is unable to perform an undo operation in an empty stack', () => {
expect(undo.canUndo()).toBe(false);
Expand Down

0 comments on commit 3536d4c

Please sign in to comment.