Skip to content

Commit

Permalink
Backport PR #148 on branch 0.2.x (Fix notebook undo scope) (#149)
Browse files Browse the repository at this point in the history
* Backport PR #148: Fix notebook undo scope

* Fix CI

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix notebook constructor call

* More constructor fixes

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
fcollonval and pre-commit-ci[bot] authored Feb 22, 2023
1 parent 8854a43 commit e4c4b6c
Show file tree
Hide file tree
Showing 7 changed files with 416 additions and 215 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
test:
name: Run tests on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 10

strategy:
matrix:
Expand Down
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v4.4.0
hooks:
- id: end-of-file-fixer
- id: check-case-conflict
Expand All @@ -16,34 +16,34 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: 22.8.0
rev: 23.1.0
hooks:
- id: black
args: ["--line-length", "100"]

- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
files: \.py$
args: [--profile=black]

- repo: https://github.com/asottile/pyupgrade
rev: v2.38.2
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py37-plus]

- repo: https://github.com/PyCQA/doc8
rev: v1.0.0
rev: v1.1.1
hooks:
- id: doc8
args: [--max-line-length=200]
exclude: docs/source/other/full-config.rst
stages: [manual]

- repo: https://github.com/pycqa/flake8
rev: 5.0.4
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies:
Expand Down
5 changes: 4 additions & 1 deletion javascript/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ export interface ISharedBase extends IDisposable {
/**
* Perform a transaction. While the function f is called, all changes to the shared
* document are bundled into a single event.
*
* @param f Transaction to execute
* @param undoable Whether to track the change in the action history or not (default `true`)
*/
transact(f: () => void): void;
transact(f: () => void, undoable?: boolean): void;
}

/**
Expand Down
18 changes: 9 additions & 9 deletions javascript/src/ymodels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
}
this.transact(() => {
this.ymodel.set('metadata', clone);
});
}, false);
} else {
const clone = JSONExt.deepCopy(metadata) as any;
if (clone.collapsed != null) {
Expand All @@ -789,7 +789,7 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
if (!JSONExt.deepEqual(clone, this.getMetadata())) {
this.transact(() => {
this.ymodel.set('metadata', clone);
});
}, false);
}
}
}
Expand All @@ -811,11 +811,11 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
* document are bundled into a single event.
*/
transact(f: () => void, undoable = true): void {
this.notebook && undoable
? this.notebook.transact(f)
: this.ymodel.doc == null
? f()
: this.ymodel.doc.transact(f, this);
!this.notebook || this.notebook.disableDocumentWideUndoRedo
? this.ymodel.doc == null
? f()
: this.ymodel.doc.transact(f, undoable ? this : null)
: this.notebook.transact(f, undoable);
}

/**
Expand Down Expand Up @@ -971,7 +971,7 @@ export class YCodeCell
if (this.ymodel.get('execution_count') !== count) {
this.transact(() => {
this.ymodel.set('execution_count', count);
});
}, false);
}
}

Expand Down Expand Up @@ -1106,7 +1106,7 @@ class YAttachmentCell
} else {
this.ymodel.set('attachments', attachments);
}
});
}, false);
}

/**
Expand Down
Loading

0 comments on commit e4c4b6c

Please sign in to comment.