Skip to content

Commit 77ce362

Browse files
javier-godoypaodb
authored andcommitted
fix: fix selection feature because of XTerm bug
Add workaround for a bug in XTerm where selecting two or more lines programmatically includes a trailing CRLF. See xtermjs/xterm.js#3552
1 parent 7492395 commit 77ce362

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/main/resources/META-INF/frontend/fc-xterm/xterm-selection-mixin.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,19 @@ class SelectionAddon extends TerminalAddon<ISelectionMixin> {
125125
if (this.__selectionAnchor!==undefined) {
126126
let buffer = (terminal.buffer.active as any)._buffer;
127127
let range = buffer.getWrappedRangeForLine(buffer.ybase+buffer.y);
128-
let pos = terminal.getSelectionPosition();
128+
let pos = terminal.getSelectionPosition();
129+
130+
//see https://github.com/xtermjs/xterm.js/issues/3552
131+
pos.endColumn==0 && --pos.endRow;
132+
129133
if (pos && pos.startRow>=range.first && pos.endRow<=range.last) {
130-
//let selectionStart = pos.startRow * terminal.cols + pos.startColumn;
131134
if (!this.__selectionRight) {
132135
//cursor backward wrapped
133-
terminal.write("\x1b[<" + this.__selectionLength + "L");
136+
if (pos.endColumn==0) {
137+
terminal.write("\x1b[<" + (this.__selectionLength-1) + "L");
138+
} else {
139+
terminal.write("\x1b[<" + this.__selectionLength + "L");
140+
}
134141
}
135142
//delete characters wrapped
136143
terminal.write("\x1b[<" + this.__selectionLength + "D");

src/test/java/com/flowingcode/vaadin/addons/xterm/integration/SelectionFeatureIT.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ public void testSelectionFeature() throws InterruptedException {
9898
term.write(text);
9999
assertThat(term.currentLine(), is(text));
100100
term.sendKeys(Keys.SHIFT, Keys.HOME);
101-
assertThat(term.getSelection(), is(text));
101+
// https://github.com/xtermjs/xterm.js/issues/3552
102+
// Selecting a whole line using API includes trailing CRLF
103+
assertThat(term.getSelection(), is(text + "\n"));
102104
term.sendKeys(Keys.DELETE);
103105
assertThat(term.currentLine(), isEmptyString());
104106

@@ -107,10 +109,9 @@ public void testSelectionFeature() throws InterruptedException {
107109
assertThat(term.currentLine(), is(text));
108110
term.sendKeys(Keys.HOME);
109111
term.sendKeys(Keys.SHIFT, Keys.END);
110-
assertThat(term.getSelection(), is(text));
112+
assertThat(term.getSelection(), is(text + "\n"));
111113
term.sendKeys(Keys.DELETE);
112114
assertThat(term.currentLine(), isEmptyString());
113-
114115
}
115116

116117
}

0 commit comments

Comments
 (0)