@codemirror/view 6.26.4 → 6.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.cjs +32 -6
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +32 -6
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -3742,9 +3742,16 @@ class InputState {
|
|
|
3742
3742
|
// (after which we retroactively handle them and reset the DOM) to
|
|
3743
3743
|
// avoid messing up the virtual keyboard state.
|
|
3744
3744
|
this.pendingIOSKey = undefined;
|
|
3745
|
+
/**
|
|
3746
|
+
When enabled (>-1), tab presses are not given to key handlers,
|
|
3747
|
+
leaving the browser's default behavior. If >0, the mode expires
|
|
3748
|
+
at that timestamp, and any other keypress clears it.
|
|
3749
|
+
Esc enables temporary tab focus mode for two seconds when not
|
|
3750
|
+
otherwise handled.
|
|
3751
|
+
*/
|
|
3752
|
+
this.tabFocusMode = -1;
|
|
3745
3753
|
this.lastSelectionOrigin = null;
|
|
3746
3754
|
this.lastSelectionTime = 0;
|
|
3747
|
-
this.lastEscPress = 0;
|
|
3748
3755
|
this.lastContextMenu = 0;
|
|
3749
3756
|
this.scrollHandlers = [];
|
|
3750
3757
|
this.handlers = Object.create(null);
|
|
@@ -3824,10 +3831,10 @@ class InputState {
|
|
|
3824
3831
|
// Must always run, even if a custom handler handled the event
|
|
3825
3832
|
this.lastKeyCode = event.keyCode;
|
|
3826
3833
|
this.lastKeyTime = Date.now();
|
|
3827
|
-
if (event.keyCode == 9 && Date.now()
|
|
3834
|
+
if (event.keyCode == 9 && this.tabFocusMode > -1 && (!this.tabFocusMode || Date.now() <= this.tabFocusMode))
|
|
3828
3835
|
return true;
|
|
3829
|
-
if (event.keyCode != 27 && modifierCodes.indexOf(event.keyCode) < 0)
|
|
3830
|
-
this.
|
|
3836
|
+
if (this.tabFocusMode > 0 && event.keyCode != 27 && modifierCodes.indexOf(event.keyCode) < 0)
|
|
3837
|
+
this.tabFocusMode = -1;
|
|
3831
3838
|
// Chrome for Android usually doesn't fire proper key events, but
|
|
3832
3839
|
// occasionally does, usually surrounded by a bunch of complicated
|
|
3833
3840
|
// composition changes. When an enter or backspace key event is
|
|
@@ -4165,8 +4172,8 @@ observers.scroll = view => {
|
|
|
4165
4172
|
};
|
|
4166
4173
|
handlers.keydown = (view, event) => {
|
|
4167
4174
|
view.inputState.setSelectionOrigin("select");
|
|
4168
|
-
if (event.keyCode == 27)
|
|
4169
|
-
view.inputState.
|
|
4175
|
+
if (event.keyCode == 27 && view.inputState.tabFocusMode != 0)
|
|
4176
|
+
view.inputState.tabFocusMode = Date.now() + 2000;
|
|
4170
4177
|
return false;
|
|
4171
4178
|
};
|
|
4172
4179
|
observers.touchstart = (view, e) => {
|
|
@@ -7881,6 +7888,25 @@ class EditorView {
|
|
|
7881
7888
|
return scrollIntoView.of(new ScrollTarget(state.EditorSelection.cursor(ref.from), "start", "start", ref.top - scrollTop, scrollLeft, true));
|
|
7882
7889
|
}
|
|
7883
7890
|
/**
|
|
7891
|
+
Enable or disable tab-focus mode, which disables key bindings
|
|
7892
|
+
for Tab and Shift-Tab, letting the browser's default
|
|
7893
|
+
focus-changing behavior go through instead. This is useful to
|
|
7894
|
+
prevent trapping keyboard users in your editor.
|
|
7895
|
+
|
|
7896
|
+
Without argument, this toggles the mode. With a boolean, it
|
|
7897
|
+
enables (true) or disables it (false). Given a number, it
|
|
7898
|
+
temporarily enables the mode until that number of milliseconds
|
|
7899
|
+
have passed or another non-Tab key is pressed.
|
|
7900
|
+
*/
|
|
7901
|
+
setTabFocusMode(to) {
|
|
7902
|
+
if (to == null)
|
|
7903
|
+
this.inputState.tabFocusMode = this.inputState.tabFocusMode < 0 ? 0 : -1;
|
|
7904
|
+
else if (typeof to == "boolean")
|
|
7905
|
+
this.inputState.tabFocusMode = to ? 0 : -1;
|
|
7906
|
+
else if (this.inputState.tabFocusMode != 0)
|
|
7907
|
+
this.inputState.tabFocusMode = Date.now() + to;
|
|
7908
|
+
}
|
|
7909
|
+
/**
|
|
7884
7910
|
Returns an extension that can be used to add DOM event handlers.
|
|
7885
7911
|
The value should be an object mapping event names to handler
|
|
7886
7912
|
functions. For any given event, such functions are ordered by
|
package/dist/index.d.cts
CHANGED
|
@@ -1092,6 +1092,18 @@ declare class EditorView {
|
|
|
1092
1092
|
*/
|
|
1093
1093
|
scrollSnapshot(): StateEffect<ScrollTarget>;
|
|
1094
1094
|
/**
|
|
1095
|
+
Enable or disable tab-focus mode, which disables key bindings
|
|
1096
|
+
for Tab and Shift-Tab, letting the browser's default
|
|
1097
|
+
focus-changing behavior go through instead. This is useful to
|
|
1098
|
+
prevent trapping keyboard users in your editor.
|
|
1099
|
+
|
|
1100
|
+
Without argument, this toggles the mode. With a boolean, it
|
|
1101
|
+
enables (true) or disables it (false). Given a number, it
|
|
1102
|
+
temporarily enables the mode until that number of milliseconds
|
|
1103
|
+
have passed or another non-Tab key is pressed.
|
|
1104
|
+
*/
|
|
1105
|
+
setTabFocusMode(to?: boolean | number): void;
|
|
1106
|
+
/**
|
|
1095
1107
|
Facet to add a [style
|
|
1096
1108
|
module](https://github.com/marijnh/style-mod#documentation) to
|
|
1097
1109
|
an editor view. The view will ensure that the module is
|
package/dist/index.d.ts
CHANGED
|
@@ -1092,6 +1092,18 @@ declare class EditorView {
|
|
|
1092
1092
|
*/
|
|
1093
1093
|
scrollSnapshot(): StateEffect<ScrollTarget>;
|
|
1094
1094
|
/**
|
|
1095
|
+
Enable or disable tab-focus mode, which disables key bindings
|
|
1096
|
+
for Tab and Shift-Tab, letting the browser's default
|
|
1097
|
+
focus-changing behavior go through instead. This is useful to
|
|
1098
|
+
prevent trapping keyboard users in your editor.
|
|
1099
|
+
|
|
1100
|
+
Without argument, this toggles the mode. With a boolean, it
|
|
1101
|
+
enables (true) or disables it (false). Given a number, it
|
|
1102
|
+
temporarily enables the mode until that number of milliseconds
|
|
1103
|
+
have passed or another non-Tab key is pressed.
|
|
1104
|
+
*/
|
|
1105
|
+
setTabFocusMode(to?: boolean | number): void;
|
|
1106
|
+
/**
|
|
1095
1107
|
Facet to add a [style
|
|
1096
1108
|
module](https://github.com/marijnh/style-mod#documentation) to
|
|
1097
1109
|
an editor view. The view will ensure that the module is
|
package/dist/index.js
CHANGED
|
@@ -3738,9 +3738,16 @@ class InputState {
|
|
|
3738
3738
|
// (after which we retroactively handle them and reset the DOM) to
|
|
3739
3739
|
// avoid messing up the virtual keyboard state.
|
|
3740
3740
|
this.pendingIOSKey = undefined;
|
|
3741
|
+
/**
|
|
3742
|
+
When enabled (>-1), tab presses are not given to key handlers,
|
|
3743
|
+
leaving the browser's default behavior. If >0, the mode expires
|
|
3744
|
+
at that timestamp, and any other keypress clears it.
|
|
3745
|
+
Esc enables temporary tab focus mode for two seconds when not
|
|
3746
|
+
otherwise handled.
|
|
3747
|
+
*/
|
|
3748
|
+
this.tabFocusMode = -1;
|
|
3741
3749
|
this.lastSelectionOrigin = null;
|
|
3742
3750
|
this.lastSelectionTime = 0;
|
|
3743
|
-
this.lastEscPress = 0;
|
|
3744
3751
|
this.lastContextMenu = 0;
|
|
3745
3752
|
this.scrollHandlers = [];
|
|
3746
3753
|
this.handlers = Object.create(null);
|
|
@@ -3820,10 +3827,10 @@ class InputState {
|
|
|
3820
3827
|
// Must always run, even if a custom handler handled the event
|
|
3821
3828
|
this.lastKeyCode = event.keyCode;
|
|
3822
3829
|
this.lastKeyTime = Date.now();
|
|
3823
|
-
if (event.keyCode == 9 && Date.now()
|
|
3830
|
+
if (event.keyCode == 9 && this.tabFocusMode > -1 && (!this.tabFocusMode || Date.now() <= this.tabFocusMode))
|
|
3824
3831
|
return true;
|
|
3825
|
-
if (event.keyCode != 27 && modifierCodes.indexOf(event.keyCode) < 0)
|
|
3826
|
-
this.
|
|
3832
|
+
if (this.tabFocusMode > 0 && event.keyCode != 27 && modifierCodes.indexOf(event.keyCode) < 0)
|
|
3833
|
+
this.tabFocusMode = -1;
|
|
3827
3834
|
// Chrome for Android usually doesn't fire proper key events, but
|
|
3828
3835
|
// occasionally does, usually surrounded by a bunch of complicated
|
|
3829
3836
|
// composition changes. When an enter or backspace key event is
|
|
@@ -4161,8 +4168,8 @@ observers.scroll = view => {
|
|
|
4161
4168
|
};
|
|
4162
4169
|
handlers.keydown = (view, event) => {
|
|
4163
4170
|
view.inputState.setSelectionOrigin("select");
|
|
4164
|
-
if (event.keyCode == 27)
|
|
4165
|
-
view.inputState.
|
|
4171
|
+
if (event.keyCode == 27 && view.inputState.tabFocusMode != 0)
|
|
4172
|
+
view.inputState.tabFocusMode = Date.now() + 2000;
|
|
4166
4173
|
return false;
|
|
4167
4174
|
};
|
|
4168
4175
|
observers.touchstart = (view, e) => {
|
|
@@ -7876,6 +7883,25 @@ class EditorView {
|
|
|
7876
7883
|
return scrollIntoView.of(new ScrollTarget(EditorSelection.cursor(ref.from), "start", "start", ref.top - scrollTop, scrollLeft, true));
|
|
7877
7884
|
}
|
|
7878
7885
|
/**
|
|
7886
|
+
Enable or disable tab-focus mode, which disables key bindings
|
|
7887
|
+
for Tab and Shift-Tab, letting the browser's default
|
|
7888
|
+
focus-changing behavior go through instead. This is useful to
|
|
7889
|
+
prevent trapping keyboard users in your editor.
|
|
7890
|
+
|
|
7891
|
+
Without argument, this toggles the mode. With a boolean, it
|
|
7892
|
+
enables (true) or disables it (false). Given a number, it
|
|
7893
|
+
temporarily enables the mode until that number of milliseconds
|
|
7894
|
+
have passed or another non-Tab key is pressed.
|
|
7895
|
+
*/
|
|
7896
|
+
setTabFocusMode(to) {
|
|
7897
|
+
if (to == null)
|
|
7898
|
+
this.inputState.tabFocusMode = this.inputState.tabFocusMode < 0 ? 0 : -1;
|
|
7899
|
+
else if (typeof to == "boolean")
|
|
7900
|
+
this.inputState.tabFocusMode = to ? 0 : -1;
|
|
7901
|
+
else if (this.inputState.tabFocusMode != 0)
|
|
7902
|
+
this.inputState.tabFocusMode = Date.now() + to;
|
|
7903
|
+
}
|
|
7904
|
+
/**
|
|
7879
7905
|
Returns an extension that can be used to add DOM event handlers.
|
|
7880
7906
|
The value should be an object mapping event names to handler
|
|
7881
7907
|
functions. For any given event, such functions are ordered by
|