Skip to content

Commit e4c4b6c

Browse files
Backport PR #148 on branch 0.2.x (Fix notebook undo scope) (#149)
* 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>
1 parent 8854a43 commit e4c4b6c

File tree

7 files changed

+416
-215
lines changed

7 files changed

+416
-215
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
test:
3131
name: Run tests on ${{ matrix.os }}
3232
runs-on: ${{ matrix.os }}
33+
timeout-minutes: 10
3334

3435
strategy:
3536
matrix:

.pre-commit-config.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v4.3.0
3+
rev: v4.4.0
44
hooks:
55
- id: end-of-file-fixer
66
- id: check-case-conflict
@@ -16,34 +16,34 @@ repos:
1616
- id: trailing-whitespace
1717

1818
- repo: https://github.com/psf/black
19-
rev: 22.8.0
19+
rev: 23.1.0
2020
hooks:
2121
- id: black
2222
args: ["--line-length", "100"]
2323

2424
- repo: https://github.com/PyCQA/isort
25-
rev: 5.10.1
25+
rev: 5.12.0
2626
hooks:
2727
- id: isort
2828
files: \.py$
2929
args: [--profile=black]
3030

3131
- repo: https://github.com/asottile/pyupgrade
32-
rev: v2.38.2
32+
rev: v3.3.1
3333
hooks:
3434
- id: pyupgrade
3535
args: [--py37-plus]
3636

3737
- repo: https://github.com/PyCQA/doc8
38-
rev: v1.0.0
38+
rev: v1.1.1
3939
hooks:
4040
- id: doc8
4141
args: [--max-line-length=200]
4242
exclude: docs/source/other/full-config.rst
4343
stages: [manual]
4444

4545
- repo: https://github.com/pycqa/flake8
46-
rev: 5.0.4
46+
rev: 6.0.0
4747
hooks:
4848
- id: flake8
4949
additional_dependencies:

javascript/src/api.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ export interface ISharedBase extends IDisposable {
6262
/**
6363
* Perform a transaction. While the function f is called, all changes to the shared
6464
* document are bundled into a single event.
65+
*
66+
* @param f Transaction to execute
67+
* @param undoable Whether to track the change in the action history or not (default `true`)
6568
*/
66-
transact(f: () => void): void;
69+
transact(f: () => void, undoable?: boolean): void;
6770
}
6871

6972
/**

javascript/src/ymodels.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
777777
}
778778
this.transact(() => {
779779
this.ymodel.set('metadata', clone);
780-
});
780+
}, false);
781781
} else {
782782
const clone = JSONExt.deepCopy(metadata) as any;
783783
if (clone.collapsed != null) {
@@ -789,7 +789,7 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
789789
if (!JSONExt.deepEqual(clone, this.getMetadata())) {
790790
this.transact(() => {
791791
this.ymodel.set('metadata', clone);
792-
});
792+
}, false);
793793
}
794794
}
795795
}
@@ -811,11 +811,11 @@ export class YBaseCell<Metadata extends nbformat.IBaseCellMetadata>
811811
* document are bundled into a single event.
812812
*/
813813
transact(f: () => void, undoable = true): void {
814-
this.notebook && undoable
815-
? this.notebook.transact(f)
816-
: this.ymodel.doc == null
817-
? f()
818-
: this.ymodel.doc.transact(f, this);
814+
!this.notebook || this.notebook.disableDocumentWideUndoRedo
815+
? this.ymodel.doc == null
816+
? f()
817+
: this.ymodel.doc.transact(f, undoable ? this : null)
818+
: this.notebook.transact(f, undoable);
819819
}
820820

821821
/**
@@ -971,7 +971,7 @@ export class YCodeCell
971971
if (this.ymodel.get('execution_count') !== count) {
972972
this.transact(() => {
973973
this.ymodel.set('execution_count', count);
974-
});
974+
}, false);
975975
}
976976
}
977977

@@ -1106,7 +1106,7 @@ class YAttachmentCell
11061106
} else {
11071107
this.ymodel.set('attachments', attachments);
11081108
}
1109-
});
1109+
}, false);
11101110
}
11111111

11121112
/**

0 commit comments

Comments
 (0)