mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
fix(tui): let drag select text over the editor
The editor consumed left mouse presses to position the cursor, which made the alternate screen route the whole gesture to it and never start its screen-level text selection. Handle the synthesized click event instead so press/drag/release stay available for selection and copy.
This commit is contained in:
parent
0e77e57d96
commit
2470ea4404
2 changed files with 31 additions and 1 deletions
|
|
@ -633,7 +633,11 @@ export class Editor implements Component, Focusable {
|
|||
return result ? { ...result, focus: true } : undefined;
|
||||
}
|
||||
|
||||
if (event.type !== "press" || event.button !== "left") return undefined;
|
||||
// Leave press/drag/release unhandled so the renderer's screen-level text
|
||||
// selection can run over the editor rows (drag to select, release to copy).
|
||||
// The renderer synthesizes a click when press and release land on the same
|
||||
// cell without movement, which is the gesture that positions the cursor.
|
||||
if (event.type !== "click" || event.button !== "left") return undefined;
|
||||
if (event.y <= 0 || event.y > this.renderedVisibleLineCount) return { handled: true, focus: true };
|
||||
|
||||
const visualLines = this.buildVisualLineMap(this.lastWidth);
|
||||
|
|
|
|||
|
|
@ -150,4 +150,30 @@ describe("mouse-aware components", () => {
|
|||
assert.strictEqual(tui.getFocusedComponent(), editor);
|
||||
tui.stop();
|
||||
});
|
||||
|
||||
it("selects and copies editor text on drag instead of moving the cursor", async () => {
|
||||
const terminal = new VirtualTerminal(20, 6);
|
||||
const copied: string[] = [];
|
||||
const tui = new TuiAltScreen(terminal, undefined, undefined, {
|
||||
copySelection: async (text) => {
|
||||
copied.push(text);
|
||||
return true;
|
||||
},
|
||||
});
|
||||
const editor = new Editor(tui, editorTheme);
|
||||
editor.setText("hello world");
|
||||
tui.addChild(editor);
|
||||
tui.start();
|
||||
await terminal.waitForRender();
|
||||
const cursorBefore = editor.getCursor();
|
||||
|
||||
terminal.sendInput("\x1b[<0;1;2M");
|
||||
terminal.sendInput("\x1b[<32;5;2M");
|
||||
terminal.sendInput("\x1b[<0;5;2m");
|
||||
await terminal.waitForRender();
|
||||
|
||||
assert.deepStrictEqual(copied, ["hello"]);
|
||||
assert.deepStrictEqual(editor.getCursor(), cursorBefore);
|
||||
tui.stop();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue