@@ -81,11 +81,12 @@ codeInput.plugins.Indent = class extends codeInput.Plugin {
8181 let indentationWidthPx = testIndentationWidthSpan . offsetWidth ;
8282 codeInput . removeChild ( testIndentationWidthPre ) ;
8383
84- codeInput . pluginData . indent = { indentationWidthPx : indentationWidthPx } ;
84+ codeInput . pluginData . indent = { automatedKeypresses : false , indentationWidthPx : indentationWidthPx } ;
8585 }
8686
8787 /* Deal with the Tab key causing indentation, and Tab+Selection indenting / Shift+Tab+Selection unindenting lines, and the mechanism through which Tab can be used to switch focus instead (accessibility). */
8888 checkTab ( codeInput , event ) {
89+ if ( codeInput . pluginData . indent . automatedKeypresses ) return ;
8990 if ( ! this . tabIndentationEnabled ) return ;
9091 if ( this . escTabToChangeFocus ) {
9192 // Accessibility - allow Tab for keyboard navigation when Esc pressed right before it.
@@ -116,7 +117,12 @@ codeInput.plugins.Indent = class extends codeInput.Plugin {
116117
117118 if ( ! event . shiftKey && inputElement . selectionStart == inputElement . selectionEnd ) {
118119 // Just place a tab/spaces here.
120+ // automatedKeypresses property to prevent keypresses being captured
121+ // by this plugin during automated input as some browsers
122+ // (e.g. GNOME Web) do.
123+ codeInput . pluginData . indent . automatedKeypresses = true ;
119124 document . execCommand ( "insertText" , false , this . indentation ) ;
125+ codeInput . pluginData . indent . automatedKeypresses = false ;
120126
121127 } else {
122128 let lines = inputElement . value . split ( "\n" ) ;
@@ -147,7 +153,12 @@ codeInput.plugins.Indent = class extends codeInput.Plugin {
147153 // Add tab at start
148154 inputElement . selectionStart = letterI ;
149155 inputElement . selectionEnd = letterI ;
156+ // automatedKeypresses property to prevent keypresses being captured
157+ // by this plugin during automated input as some browsers
158+ // (e.g. GNOME Web) do.
159+ codeInput . pluginData . indent . f = true ;
150160 document . execCommand ( "insertText" , false , this . indentation ) ;
161+ codeInput . pluginData . indent . automatedKeypresses = false ;
151162
152163 // Change selection
153164 if ( selectionStartI > letterI ) { // Indented outside selection
@@ -191,6 +202,7 @@ codeInput.plugins.Indent = class extends codeInput.Plugin {
191202
192203 /* Deal with new lines retaining indentation */
193204 checkEnter ( codeInput , event ) {
205+ if ( codeInput . pluginData . indent . automatedKeypresses ) return ;
194206 if ( event . key != "Enter" ) {
195207 return ;
196208 }
@@ -270,11 +282,16 @@ codeInput.plugins.Indent = class extends codeInput.Plugin {
270282 // save the current cursor position
271283 let selectionStartI = inputElement . selectionStart ;
272284
285+ // automatedKeypresses property to prevent keypresses being captured
286+ // by this plugin during automated input as some browsers
287+ // (e.g. GNOME Web) do.
288+ codeInput . pluginData . indent . automatedKeypresses = true ;
273289 if ( bracketThreeLinesTriggered ) {
274290 document . execCommand ( "insertText" , false , "\n" + furtherIndentation ) ; // Write indented line
275291 numberIndents += 1 ; // Reflects the new indent
276292 }
277293 document . execCommand ( "insertText" , false , "\n" + newLine ) ; // Write new line, including auto-indentation
294+ codeInput . pluginData . indent . automatedKeypresses = false ;
278295
279296 // move cursor to new position
280297 inputElement . selectionStart = selectionStartI + numberIndents * this . indentationNumChars + 1 ; // count the indent level and the newline character
@@ -294,6 +311,7 @@ codeInput.plugins.Indent = class extends codeInput.Plugin {
294311
295312 /* Deal with one 'tab' of spaces-based-indentation being deleted by each backspace, rather than one space */
296313 checkBackspace ( codeInput , event ) {
314+ if ( codeInput . pluginData . indent . automatedKeypresses ) return ;
297315 if ( event . key != "Backspace" || this . indentationNumChars == 1 ) {
298316 return ; // Normal backspace when indentation of 1
299317 }
0 commit comments