From d3adbd03d4788fab34ac8313fc79c584e0276978 Mon Sep 17 00:00:00 2001 From: Clem Fern Date: Fri, 28 Apr 2023 20:03:55 +0200 Subject: [PATCH] fix(tabby-terminal): prevent copying on select when search find next/previous --- tabby-terminal/src/frontends/xtermFrontend.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tabby-terminal/src/frontends/xtermFrontend.ts b/tabby-terminal/src/frontends/xtermFrontend.ts index fe6b7dc2..88951c2a 100644 --- a/tabby-terminal/src/frontends/xtermFrontend.ts +++ b/tabby-terminal/src/frontends/xtermFrontend.ts @@ -69,6 +69,7 @@ export class XTermFrontend extends Frontend { private resizeHandler: () => void private configuredTheme: ITheme = {} private copyOnSelect = false + private preventNextOnSelectionChangeEvent = false private search = new SearchAddon() private searchState: SearchState = { resultCount: 0 } private fitAddon = new FitAddon() @@ -116,8 +117,11 @@ export class XTermFrontend extends Frontend { this.title.next(title) }) this.xterm.onSelectionChange(() => { - if (this.copyOnSelect && this.getSelection()) { - this.copySelection() + if (this.getSelection()) { + if (this.copyOnSelect && !this.preventNextOnSelectionChangeEvent) { + this.copySelection() + } + this.preventNextOnSelectionChangeEvent = false } }) this.xterm.onBell(() => { @@ -444,12 +448,18 @@ export class XTermFrontend extends Frontend { } findNext (term: string, searchOptions?: SearchOptions): SearchState { + if (this.copyOnSelect) { + this.preventNextOnSelectionChangeEvent = true + } return this.wrapSearchResult( this.search.findNext(term, this.getSearchOptions(searchOptions)), ) } findPrevious (term: string, searchOptions?: SearchOptions): SearchState { + if (this.copyOnSelect) { + this.preventNextOnSelectionChangeEvent = true + } return this.wrapSearchResult( this.search.findPrevious(term, this.getSearchOptions(searchOptions)), )