brsh 3.3.0 → 3.3.1
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 +7 -0
- package/dist/terminal.cjs.js +3 -3
- package/dist/terminal.cjs.js.map +1 -1
- package/dist/terminal.es.js +58 -13
- package/dist/terminal.es.js.map +1 -1
- package/dist/terminal.min.js +3 -3
- package/dist/terminal.min.js.map +1 -1
- package/lib/Terminal.js +113 -11
- package/package.json +1 -1
- package/test/terminal.test.js +126 -0
package/lib/Terminal.js
CHANGED
|
@@ -261,6 +261,10 @@ class Terminal {
|
|
|
261
261
|
this._flushTypeQueue();
|
|
262
262
|
this.parser.reset();
|
|
263
263
|
this.renderer.flushRender();
|
|
264
|
+
this._mobileInputBuffer = '';
|
|
265
|
+
if (this._mobileInputElement) {
|
|
266
|
+
this._mobileInputElement.value = '';
|
|
267
|
+
}
|
|
264
268
|
}
|
|
265
269
|
|
|
266
270
|
/**
|
|
@@ -528,6 +532,10 @@ class Terminal {
|
|
|
528
532
|
this._autoScroll();
|
|
529
533
|
}
|
|
530
534
|
const isPureEnter = data === '\r' || data === '\n' || data === '\r\n';
|
|
535
|
+
if (isPureEnter && this._mobileInputElement) {
|
|
536
|
+
this._mobileInputElement.value = '';
|
|
537
|
+
this._mobileInputBuffer = '';
|
|
538
|
+
}
|
|
531
539
|
this._suppressAnimationUntil = isPureEnter ? 0 : Date.now() + 80;
|
|
532
540
|
this._isHandlingInput = !isPureEnter;
|
|
533
541
|
try {
|
|
@@ -884,6 +892,11 @@ class Terminal {
|
|
|
884
892
|
input.style.zIndex = '-1';
|
|
885
893
|
input.setAttribute('aria-hidden', 'true');
|
|
886
894
|
input.setAttribute('tabindex', '-1');
|
|
895
|
+
input.setAttribute('autocapitalize', 'none');
|
|
896
|
+
input.setAttribute('autocorrect', 'off');
|
|
897
|
+
input.setAttribute('autocomplete', 'off');
|
|
898
|
+
input.setAttribute('spellcheck', 'false');
|
|
899
|
+
input.setAttribute('enterkeyhint', 'go');
|
|
887
900
|
this._el.appendChild(input);
|
|
888
901
|
this._mobileInputElement = input;
|
|
889
902
|
this._mobileInputBuffer = '';
|
|
@@ -893,28 +906,117 @@ class Terminal {
|
|
|
893
906
|
if (e && e.target && e.target.tagName === 'A') return;
|
|
894
907
|
if (typeof input.focus === 'function') {
|
|
895
908
|
input.focus({ preventScroll: true });
|
|
909
|
+
if (typeof input.setSelectionRange === 'function') {
|
|
910
|
+
const len = (input.value || '').length;
|
|
911
|
+
input.setSelectionRange(len, len);
|
|
912
|
+
}
|
|
896
913
|
}
|
|
897
914
|
};
|
|
898
915
|
this._el.addEventListener('click', this._onMobileInputClick);
|
|
899
916
|
|
|
900
|
-
|
|
901
|
-
|
|
917
|
+
const applyDiff = () => {
|
|
918
|
+
const oldVal = this._mobileInputBuffer || '';
|
|
919
|
+
const newVal = input.value || '';
|
|
920
|
+
if (oldVal === newVal) return;
|
|
921
|
+
|
|
922
|
+
let prefix = 0;
|
|
923
|
+
while (prefix < oldVal.length && prefix < newVal.length && oldVal[prefix] === newVal[prefix]) {
|
|
924
|
+
prefix++;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
let suffix = 0;
|
|
928
|
+
while (
|
|
929
|
+
suffix < (oldVal.length - prefix) &&
|
|
930
|
+
suffix < (newVal.length - prefix) &&
|
|
931
|
+
oldVal[oldVal.length - 1 - suffix] === newVal[newVal.length - 1 - suffix]
|
|
932
|
+
) {
|
|
933
|
+
suffix++;
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
const deletedCount = oldVal.length - prefix - suffix;
|
|
937
|
+
const insertedText = newVal.slice(prefix, newVal.length - suffix);
|
|
938
|
+
|
|
939
|
+
if (deletedCount > 0) {
|
|
940
|
+
for (let i = 0; i < deletedCount; i++) {
|
|
941
|
+
this.sendKey('Backspace');
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
if (insertedText) {
|
|
946
|
+
const normalized = insertedText.replace(/\r?\n/g, '\r');
|
|
947
|
+
this._emitInput(normalized);
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
this._mobileInputBuffer = newVal;
|
|
951
|
+
};
|
|
952
|
+
|
|
953
|
+
const onInput = (e) => {
|
|
954
|
+
if (!e) {
|
|
955
|
+
applyDiff();
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
const inputType = e.inputType;
|
|
960
|
+
if (inputType === 'insertLineBreak' || inputType === 'insertParagraph') {
|
|
961
|
+
this.sendKey('Enter');
|
|
902
962
|
input.value = '';
|
|
903
|
-
this._mobileInputBuffer =
|
|
963
|
+
this._mobileInputBuffer = '';
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
if (inputType === 'deleteContentBackward') {
|
|
968
|
+
this.sendKey('Backspace');
|
|
969
|
+
this._mobileInputBuffer = input.value || '';
|
|
970
|
+
return;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
if (inputType === 'deleteContentForward') {
|
|
974
|
+
this.sendKey('Delete');
|
|
975
|
+
this._mobileInputBuffer = input.value || '';
|
|
976
|
+
return;
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
if (inputType === 'deleteWordBackward') {
|
|
980
|
+
this.sendKey('Backspace', { alt: true });
|
|
981
|
+
this._mobileInputBuffer = input.value || '';
|
|
982
|
+
return;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
if (inputType === 'insertText' && typeof e.data === 'string' && e.data.length > 0) {
|
|
986
|
+
const expectedLen = (this._mobileInputBuffer || '').length + e.data.length;
|
|
987
|
+
if (!input.value || input.value.length === expectedLen) {
|
|
988
|
+
const normalized = e.data.replace(/\r?\n/g, '\r');
|
|
989
|
+
this._emitInput(normalized);
|
|
990
|
+
this._mobileInputBuffer = input.value || '';
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
applyDiff();
|
|
996
|
+
};
|
|
997
|
+
|
|
998
|
+
input.addEventListener('input', onInput);
|
|
999
|
+
|
|
1000
|
+
input.addEventListener('keydown', (e) => {
|
|
1001
|
+
if (e && (e.key === 'Enter' || e.keyCode === 13)) {
|
|
1002
|
+
if (!e.defaultPrevented) {
|
|
1003
|
+
this.sendKey('Enter');
|
|
1004
|
+
input.value = '';
|
|
1005
|
+
this._mobileInputBuffer = '';
|
|
1006
|
+
if (e.preventDefault) e.preventDefault();
|
|
1007
|
+
}
|
|
904
1008
|
}
|
|
905
1009
|
});
|
|
906
1010
|
|
|
907
1011
|
input.addEventListener('keyup', (e) => {
|
|
908
|
-
if (e.key === 'Unidentified') {
|
|
909
|
-
|
|
910
|
-
this.sendKey('Backspace');
|
|
911
|
-
} else if (input.value.length > this._mobileInputBuffer.length) {
|
|
912
|
-
const char = input.value[input.value.length - 1];
|
|
913
|
-
this.sendKey(char);
|
|
914
|
-
}
|
|
915
|
-
this._mobileInputBuffer = input.value;
|
|
1012
|
+
if (e && e.key === 'Unidentified') {
|
|
1013
|
+
applyDiff();
|
|
916
1014
|
}
|
|
917
1015
|
});
|
|
1016
|
+
|
|
1017
|
+
input.addEventListener('compositionend', () => {
|
|
1018
|
+
applyDiff();
|
|
1019
|
+
});
|
|
918
1020
|
}
|
|
919
1021
|
|
|
920
1022
|
_autoScroll() {
|
package/package.json
CHANGED
package/test/terminal.test.js
CHANGED
|
@@ -882,5 +882,131 @@ describe('Output Typing Animation Suppression', () => {
|
|
|
882
882
|
expect(el.children).not.toContain(input);
|
|
883
883
|
expect(term._mobileInputElement).toBeNull();
|
|
884
884
|
});
|
|
885
|
+
|
|
886
|
+
it('disables autocapitalize, autocorrect, autocomplete, and spellcheck on mobile input', () => {
|
|
887
|
+
const el = document.createElement('div');
|
|
888
|
+
const term = new Terminal({
|
|
889
|
+
el,
|
|
890
|
+
Shell: false,
|
|
891
|
+
mobileInput: 'click'
|
|
892
|
+
});
|
|
893
|
+
|
|
894
|
+
const input = term._mobileInputElement;
|
|
895
|
+
expect(input.autocapitalize).toBe('none');
|
|
896
|
+
expect(input.autocorrect).toBe('off');
|
|
897
|
+
expect(input.autocomplete).toBe('off');
|
|
898
|
+
expect(input.spellcheck).toBe('false');
|
|
899
|
+
expect(input.enterkeyhint).toBe('go');
|
|
900
|
+
term.destroy();
|
|
901
|
+
});
|
|
902
|
+
|
|
903
|
+
it('handles mobile character typing when characters are prepended due to zero caret', () => {
|
|
904
|
+
const el = document.createElement('div');
|
|
905
|
+
const term = new Terminal({
|
|
906
|
+
el,
|
|
907
|
+
Shell: false,
|
|
908
|
+
mobileInput: 'click'
|
|
909
|
+
});
|
|
910
|
+
|
|
911
|
+
const input = term._mobileInputElement;
|
|
912
|
+
const received = [];
|
|
913
|
+
term.onData((data) => received.push(data));
|
|
914
|
+
|
|
915
|
+
// Type 'h'
|
|
916
|
+
input.value = 'h';
|
|
917
|
+
input.dispatchEvent('input');
|
|
918
|
+
|
|
919
|
+
// Type 'e' (prepended at offset 0 due to zero-size input caret, value becomes 'eh')
|
|
920
|
+
input.value = 'eh';
|
|
921
|
+
input.dispatchEvent('input');
|
|
922
|
+
|
|
923
|
+
// Type 'l' (prepended at offset 0, value becomes 'leh')
|
|
924
|
+
input.value = 'leh';
|
|
925
|
+
input.dispatchEvent('input');
|
|
926
|
+
|
|
927
|
+
// Type 'p' (prepended at offset 0, value becomes 'pleh')
|
|
928
|
+
input.value = 'pleh';
|
|
929
|
+
input.dispatchEvent('input');
|
|
930
|
+
|
|
931
|
+
expect(received).toEqual(['h', 'e', 'l', 'p']);
|
|
932
|
+
term.destroy();
|
|
933
|
+
});
|
|
934
|
+
|
|
935
|
+
it('handles mobile typing via inputType insertText and e.data', () => {
|
|
936
|
+
const el = document.createElement('div');
|
|
937
|
+
const term = new Terminal({
|
|
938
|
+
el,
|
|
939
|
+
Shell: false,
|
|
940
|
+
mobileInput: 'click'
|
|
941
|
+
});
|
|
942
|
+
|
|
943
|
+
const input = term._mobileInputElement;
|
|
944
|
+
const received = [];
|
|
945
|
+
term.onData((data) => received.push(data));
|
|
946
|
+
|
|
947
|
+
input.value = 'a';
|
|
948
|
+
input.dispatchEvent('input', { inputType: 'insertText', data: 'a' });
|
|
949
|
+
|
|
950
|
+
input.value = 'ab';
|
|
951
|
+
input.dispatchEvent('input', { inputType: 'insertText', data: 'b' });
|
|
952
|
+
|
|
953
|
+
input.value = 'abc';
|
|
954
|
+
input.dispatchEvent('input', { inputType: 'insertText', data: 'c' });
|
|
955
|
+
|
|
956
|
+
expect(received).toEqual(['a', 'b', 'c']);
|
|
957
|
+
term.destroy();
|
|
958
|
+
});
|
|
959
|
+
|
|
960
|
+
it('handles mobile backspace and Enter', () => {
|
|
961
|
+
const el = document.createElement('div');
|
|
962
|
+
const term = new Terminal({
|
|
963
|
+
el,
|
|
964
|
+
Shell: false,
|
|
965
|
+
mobileInput: 'click'
|
|
966
|
+
});
|
|
967
|
+
|
|
968
|
+
const input = term._mobileInputElement;
|
|
969
|
+
const received = [];
|
|
970
|
+
term.onData((data) => received.push(data));
|
|
971
|
+
|
|
972
|
+
// Type 'hi'
|
|
973
|
+
input.value = 'hi';
|
|
974
|
+
input.dispatchEvent('input', { inputType: 'insertText', data: 'hi' });
|
|
975
|
+
|
|
976
|
+
// Backspace via inputType
|
|
977
|
+
input.value = 'h';
|
|
978
|
+
input.dispatchEvent('input', { inputType: 'deleteContentBackward' });
|
|
979
|
+
|
|
980
|
+
// Enter via insertLineBreak
|
|
981
|
+
input.dispatchEvent('input', { inputType: 'insertLineBreak' });
|
|
982
|
+
|
|
983
|
+
expect(received).toEqual(['hi', '\x7f', '\r']);
|
|
984
|
+
expect(input.value).toBe('');
|
|
985
|
+
expect(term._mobileInputBuffer).toBe('');
|
|
986
|
+
|
|
987
|
+
term.destroy();
|
|
988
|
+
});
|
|
989
|
+
|
|
990
|
+
it('handles Android keyup with Unidentified via diff', () => {
|
|
991
|
+
const el = document.createElement('div');
|
|
992
|
+
const term = new Terminal({
|
|
993
|
+
el,
|
|
994
|
+
Shell: false,
|
|
995
|
+
mobileInput: 'click'
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
const input = term._mobileInputElement;
|
|
999
|
+
const received = [];
|
|
1000
|
+
term.onData((data) => received.push(data));
|
|
1001
|
+
|
|
1002
|
+
input.value = 'x';
|
|
1003
|
+
input.dispatchEvent('keyup', { key: 'Unidentified' });
|
|
1004
|
+
|
|
1005
|
+
input.value = 'yx'; // prepended 'y'
|
|
1006
|
+
input.dispatchEvent('keyup', { key: 'Unidentified' });
|
|
1007
|
+
|
|
1008
|
+
expect(received).toEqual(['x', 'y']);
|
|
1009
|
+
term.destroy();
|
|
1010
|
+
});
|
|
885
1011
|
});
|
|
886
1012
|
});
|