From 74d8afc549b9c6a2753c9dc109fe3a762025b2db Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Mon, 27 Jan 2025 21:33:17 +0100 Subject: [PATCH 01/14] Automatically expand removal for Tree sitter targets --- .../processTargets/targets/ScopeTypeTarget.ts | 30 +++++--- .../getSmartRemovalTarget.ts | 72 +++++++++++++++++++ 2 files changed, 94 insertions(+), 8 deletions(-) create mode 100644 packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts diff --git a/packages/cursorless-engine/src/processTargets/targets/ScopeTypeTarget.ts b/packages/cursorless-engine/src/processTargets/targets/ScopeTypeTarget.ts index ca757840fe..12120ca0f6 100644 --- a/packages/cursorless-engine/src/processTargets/targets/ScopeTypeTarget.ts +++ b/packages/cursorless-engine/src/processTargets/targets/ScopeTypeTarget.ts @@ -1,17 +1,19 @@ import type { Range, SimpleScopeTypeType } from "@cursorless/common"; +import type { Target } from "../../typings/target.types"; import type { CommonTargetParameters } from "./BaseTarget"; import { BaseTarget } from "./BaseTarget"; import { InteriorTarget } from "./InteriorTarget"; import { PlainTarget } from "./PlainTarget"; -import type { Target } from "../../typings/target.types"; import { createContinuousRange, createContinuousRangeFromRanges, } from "./util/createContinuousRange"; -import { getDelimitedSequenceRemovalRange } from "./util/insertionRemovalBehaviors/DelimitedSequenceInsertionRemovalBehavior"; +import { + getDelimitedSequenceRemovalRange, + getSmartRemovalTarget, +} from "./util/insertionRemovalBehaviors/DelimitedSequenceInsertionRemovalBehavior"; import { getTokenLeadingDelimiterTarget, - getTokenRemovalRange, getTokenTrailingDelimiterTarget, } from "./util/insertionRemovalBehaviors/TokenInsertionRemovalBehavior"; @@ -93,11 +95,23 @@ export class ScopeTypeTarget extends BaseTarget { } getRemovalRange(): Range { - return this.removalRange_ != null - ? this.removalRange_ - : this.hasDelimiterRange_ - ? getDelimitedSequenceRemovalRange(this) - : getTokenRemovalRange(this); + if (this.removalRange_ != null) { + return this.removalRange_; + } + if (this.hasDelimiterRange_) { + return getDelimitedSequenceRemovalRange(this); + } + return getSmartRemovalTarget(this).getRemovalRange(); + } + + getRemovalHighlightRange(): Range { + if (this.removalRange_ != null) { + return this.removalRange_; + } + if (this.hasDelimiterRange_) { + return getDelimitedSequenceRemovalRange(this); + } + return getSmartRemovalTarget(this).getRemovalHighlightRange(); } maybeCreateRichRangeTarget( diff --git a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts new file mode 100644 index 0000000000..16981f1b83 --- /dev/null +++ b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts @@ -0,0 +1,72 @@ +import type { Range, TextDocument, TextEditor } from "@cursorless/common"; +import type { Target } from "../../../../typings/target.types"; +import { shrinkRangeToFitContent } from "../../../../util/selectionUtils"; +import { DocumentTarget } from "../../DocumentTarget"; +import { LineTarget } from "../../LineTarget"; +import { ParagraphTarget } from "../../ParagraphTarget"; +import { TokenTarget } from "../../TokenTarget"; +import { union } from "../../../../util/rangeUtils"; + +export function getSmartRemovalTarget(target: Target): Target { + const { editor, isReversed } = target; + const { document } = editor; + const contentRange = union(target.contentRange, target.prefixRange); + + if (!isLine(document, contentRange)) { + return new TokenTarget({ + editor, + isReversed, + contentRange: contentRange, + }); + } + + if (isDocument(editor, contentRange)) { + return new DocumentTarget({ + editor, + isReversed, + contentRange: document.range, + }); + } + + if (isParagraph(document, contentRange)) { + return new ParagraphTarget({ + editor, + isReversed, + contentRange: contentRange, + }); + } + + return new LineTarget({ + editor, + isReversed, + contentRange: contentRange, + }); +} + +function isLine(document: TextDocument, contentRange: Range): boolean { + const start = document.lineAt(contentRange.start).rangeTrimmed?.start; + const end = document.lineAt(contentRange.end).rangeTrimmed?.end; + return ( + start != null && + end != null && + start.isEqual(contentRange.start) && + end.isEqual(contentRange.end) + ); +} + +function isParagraph(document: TextDocument, contentRange: Range): boolean { + const { start, end } = contentRange; + return ( + (start.line === 0 || document.lineAt(start.line - 1).isEmptyOrWhitespace) && + (end.line === document.lineCount - 1 || + document.lineAt(end.line + 1).isEmptyOrWhitespace) + ); +} + +function isDocument(editor: TextEditor, contentRange: Range): boolean { + const documentContentRange = shrinkRangeToFitContent( + editor, + editor.document.range, + ); + return documentContentRange.isRangeEqual(contentRange); +} From fece2af2c45ef9084c7974cc437b1b862ea8f9da Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Mon, 27 Jan 2025 21:34:33 +0100 Subject: [PATCH 02/14] Update imports --- .../src/processTargets/targets/ScopeTypeTarget.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/cursorless-engine/src/processTargets/targets/ScopeTypeTarget.ts b/packages/cursorless-engine/src/processTargets/targets/ScopeTypeTarget.ts index 12120ca0f6..20479540ec 100644 --- a/packages/cursorless-engine/src/processTargets/targets/ScopeTypeTarget.ts +++ b/packages/cursorless-engine/src/processTargets/targets/ScopeTypeTarget.ts @@ -8,14 +8,12 @@ import { createContinuousRange, createContinuousRangeFromRanges, } from "./util/createContinuousRange"; -import { - getDelimitedSequenceRemovalRange, - getSmartRemovalTarget, -} from "./util/insertionRemovalBehaviors/DelimitedSequenceInsertionRemovalBehavior"; +import { getDelimitedSequenceRemovalRange } from "./util/insertionRemovalBehaviors/DelimitedSequenceInsertionRemovalBehavior"; import { getTokenLeadingDelimiterTarget, getTokenTrailingDelimiterTarget, } from "./util/insertionRemovalBehaviors/TokenInsertionRemovalBehavior"; +import { getSmartRemovalTarget } from "./util/insertionRemovalBehaviors/getSmartRemovalTarget"; export interface ScopeTypeTargetParameters extends CommonTargetParameters { readonly scopeTypeType: SimpleScopeTypeType; From 4874b1facb86800e431afb01ae533e9e9f79c8c6 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Mon, 27 Jan 2025 21:35:12 +0100 Subject: [PATCH 03/14] Order imports --- .../util/insertionRemovalBehaviors/getSmartRemovalTarget.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts index 16981f1b83..9d650dca8a 100644 --- a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts +++ b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts @@ -1,11 +1,11 @@ import type { Range, TextDocument, TextEditor } from "@cursorless/common"; import type { Target } from "../../../../typings/target.types"; +import { union } from "../../../../util/rangeUtils"; import { shrinkRangeToFitContent } from "../../../../util/selectionUtils"; import { DocumentTarget } from "../../DocumentTarget"; import { LineTarget } from "../../LineTarget"; import { ParagraphTarget } from "../../ParagraphTarget"; import { TokenTarget } from "../../TokenTarget"; -import { union } from "../../../../util/rangeUtils"; export function getSmartRemovalTarget(target: Target): Target { const { editor, isReversed } = target; From 491b2ee7bcd4aae7f2ee88ae1f16f3f0bb6ab7e6 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Tue, 28 Jan 2025 08:13:05 +0100 Subject: [PATCH 04/14] Update test fixtures --- .../recorded/itemTextual/chuckItem2.yml | 1 - .../recorded/languages/css/chuckState2.yml | 3 +- .../recorded/languages/ruby/chuckState.yml | 1 - .../recorded/languages/ruby/chuckState10.yml | 1 - .../recorded/languages/ruby/chuckState11.yml | 1 - .../recorded/languages/ruby/chuckState2.yml | 1 - .../recorded/languages/ruby/chuckState3.yml | 1 - .../recorded/languages/ruby/chuckState4.yml | 1 - .../recorded/languages/ruby/chuckState5.yml | 1 - .../recorded/languages/ruby/chuckState7.yml | 1 - .../recorded/languages/ruby/chuckState8.yml | 1 - .../recorded/languages/ruby/chuckState9.yml | 1 - .../recorded/languages/rust/chuckFunkMade.yml | 7 ++-- .../recorded/languages/rust/chuckState.yml | 3 +- .../recorded/languages/rust/chuckTypeAir.yml | 6 +-- .../recorded/languages/rust/chuckTypeMade.yml | 8 ++-- .../languages/scala/chuckBranchSun.yml | 5 +-- .../recorded/languages/scss/chuckState2.yml | 3 +- .../languages/typescript/chuckState.yml | 1 - .../languages/typescript/chuckState2.yml | 1 - .../languages/typescript/ditchFunk.yml | 1 - .../languages/typescript/ditchFunk2.yml | 1 - .../recorded/languages/yaml/chuckItem11.yml | 7 ++-- data/fixtures/scopes/c/class.scope | 42 ++++++++++++++++--- data/fixtures/scopes/c/ifStatement.scope | 6 ++- data/fixtures/scopes/c/statement.class.scope | 42 ++++++++++++++++--- data/fixtures/scopes/c/type.class.scope | 42 ++++++++++++++++--- data/fixtures/scopes/cpp/class.scope | 14 ++++++- data/fixtures/scopes/cpp/ifStatement.scope | 6 ++- .../fixtures/scopes/cpp/statement.class.scope | 14 ++++++- data/fixtures/scopes/cpp/type.class.scope | 14 ++++++- .../csharp/namedFunction.constructor.scope | 6 ++- .../scopes/csharp/namedFunction.method.scope | 6 ++- data/fixtures/scopes/dart/ifStatement.scope | 6 ++- data/fixtures/scopes/java/branch.if.scope | 14 ++++++- data/fixtures/scopes/java/branch.try.scope | 21 ++++++++-- .../java/collectionItem.unenclosed2.scope | 5 ++- .../scopes/javascript.core/branch.if.scope | 18 +++++++- .../javascript.core/branch.switchCase.scope | 12 ++++-- .../scopes/javascript.core/branch.try.scope | 27 ++++++++++-- .../namedFunction.constructor.scope | 6 ++- .../namedFunction.method.scope | 6 ++- data/fixtures/scopes/jsonl/map.scope | 14 ++++++- data/fixtures/scopes/latex/endTag.scope | 9 +++- data/fixtures/scopes/latex/startTag.scope | 9 +++- data/fixtures/scopes/latex/tags.scope | 18 ++++++-- data/fixtures/scopes/lua/branch.if.scope | 24 +++++++++-- .../markdown/collectionItem.unenclosed.scope | 6 ++- .../scopes/markdown/notebookCell.scope | 21 +++++++++- data/fixtures/scopes/php/comment.block.scope | 6 ++- data/fixtures/scopes/php/comment.line.scope | 6 ++- data/fixtures/scopes/php/comment.line2.scope | 6 ++- data/fixtures/scopes/python/branch.if.scope | 24 +++++++++-- data/fixtures/scopes/python/branch.loop.scope | 16 ++++++- .../fixtures/scopes/python/branch.loop2.scope | 16 ++++++- .../scopes/python/branch.switchCase.scope | 10 +++-- data/fixtures/scopes/python/branch.try.scope | 24 +++++++++-- data/fixtures/scopes/python/branch.try2.scope | 24 +++++++++-- .../scopes/rust/string.singleLine.scope | 21 ++++++++-- .../textual/collectionItem.textual12.scope | 7 +++- .../textual/collectionItem.textual15.scope | 6 ++- .../namedFunction.constructor.scope | 18 +++++--- .../namedFunction.method.scope | 18 +++++--- .../typescript.core/namedFunction.scope | 21 ++++++++-- .../scopes/typescript.core/statement.scope | 6 ++- 65 files changed, 535 insertions(+), 159 deletions(-) diff --git a/data/fixtures/recorded/itemTextual/chuckItem2.yml b/data/fixtures/recorded/itemTextual/chuckItem2.yml index 3ca57fff37..dcb3d26f9d 100644 --- a/data/fixtures/recorded/itemTextual/chuckItem2.yml +++ b/data/fixtures/recorded/itemTextual/chuckItem2.yml @@ -22,7 +22,6 @@ initialState: finalState: documentContents: |- [ - ] selections: - anchor: {line: 1, character: 0} diff --git a/data/fixtures/recorded/languages/css/chuckState2.yml b/data/fixtures/recorded/languages/css/chuckState2.yml index 733559219c..db00707a4d 100644 --- a/data/fixtures/recorded/languages/css/chuckState2.yml +++ b/data/fixtures/recorded/languages/css/chuckState2.yml @@ -22,8 +22,7 @@ initialState: active: {line: 0, character: 2} marks: {} finalState: - documentContents: |+ - + documentContents: "" selections: - anchor: {line: 0, character: 0} active: {line: 0, character: 0} diff --git a/data/fixtures/recorded/languages/ruby/chuckState.yml b/data/fixtures/recorded/languages/ruby/chuckState.yml index 7222f78c8d..3e82765a54 100644 --- a/data/fixtures/recorded/languages/ruby/chuckState.yml +++ b/data/fixtures/recorded/languages/ruby/chuckState.yml @@ -22,7 +22,6 @@ initialState: finalState: documentContents: |- if true - end selections: - anchor: {line: 1, character: 0} diff --git a/data/fixtures/recorded/languages/ruby/chuckState10.yml b/data/fixtures/recorded/languages/ruby/chuckState10.yml index 32b449af03..a00f651821 100644 --- a/data/fixtures/recorded/languages/ruby/chuckState10.yml +++ b/data/fixtures/recorded/languages/ruby/chuckState10.yml @@ -26,7 +26,6 @@ finalState: begin a = 10 ensure - end selections: - anchor: {line: 3, character: 0} diff --git a/data/fixtures/recorded/languages/ruby/chuckState11.yml b/data/fixtures/recorded/languages/ruby/chuckState11.yml index 0707ace4a7..f0da41758d 100644 --- a/data/fixtures/recorded/languages/ruby/chuckState11.yml +++ b/data/fixtures/recorded/languages/ruby/chuckState11.yml @@ -28,7 +28,6 @@ finalState: begin a = 10 else - ensure a = 10 end diff --git a/data/fixtures/recorded/languages/ruby/chuckState2.yml b/data/fixtures/recorded/languages/ruby/chuckState2.yml index 85b2eec822..2c2e3a71fb 100644 --- a/data/fixtures/recorded/languages/ruby/chuckState2.yml +++ b/data/fixtures/recorded/languages/ruby/chuckState2.yml @@ -22,7 +22,6 @@ initialState: finalState: documentContents: |- while true do - end selections: - anchor: {line: 1, character: 0} diff --git a/data/fixtures/recorded/languages/ruby/chuckState3.yml b/data/fixtures/recorded/languages/ruby/chuckState3.yml index edfd3ea45d..3aaf87c44f 100644 --- a/data/fixtures/recorded/languages/ruby/chuckState3.yml +++ b/data/fixtures/recorded/languages/ruby/chuckState3.yml @@ -22,7 +22,6 @@ initialState: finalState: documentContents: |- [].each do |i| - end selections: - anchor: {line: 1, character: 0} diff --git a/data/fixtures/recorded/languages/ruby/chuckState4.yml b/data/fixtures/recorded/languages/ruby/chuckState4.yml index 8071ebc937..41b18ec4ed 100644 --- a/data/fixtures/recorded/languages/ruby/chuckState4.yml +++ b/data/fixtures/recorded/languages/ruby/chuckState4.yml @@ -22,7 +22,6 @@ initialState: finalState: documentContents: |- [].each { |i| - } selections: - anchor: {line: 1, character: 0} diff --git a/data/fixtures/recorded/languages/ruby/chuckState5.yml b/data/fixtures/recorded/languages/ruby/chuckState5.yml index 0dd33de485..fccd9b2edb 100644 --- a/data/fixtures/recorded/languages/ruby/chuckState5.yml +++ b/data/fixtures/recorded/languages/ruby/chuckState5.yml @@ -22,7 +22,6 @@ initialState: finalState: documentContents: |- begin - end until true selections: - anchor: {line: 1, character: 0} diff --git a/data/fixtures/recorded/languages/ruby/chuckState7.yml b/data/fixtures/recorded/languages/ruby/chuckState7.yml index a707db7c71..32a9db8b2d 100644 --- a/data/fixtures/recorded/languages/ruby/chuckState7.yml +++ b/data/fixtures/recorded/languages/ruby/chuckState7.yml @@ -26,7 +26,6 @@ finalState: documentContents: |- case abc when true - else a = 10 end diff --git a/data/fixtures/recorded/languages/ruby/chuckState8.yml b/data/fixtures/recorded/languages/ruby/chuckState8.yml index 3099c76fe1..2e3f7a1993 100644 --- a/data/fixtures/recorded/languages/ruby/chuckState8.yml +++ b/data/fixtures/recorded/languages/ruby/chuckState8.yml @@ -28,7 +28,6 @@ finalState: when true a = 0 else - end selections: - anchor: {line: 4, character: 0} diff --git a/data/fixtures/recorded/languages/ruby/chuckState9.yml b/data/fixtures/recorded/languages/ruby/chuckState9.yml index 40b477c202..6d819ff017 100644 --- a/data/fixtures/recorded/languages/ruby/chuckState9.yml +++ b/data/fixtures/recorded/languages/ruby/chuckState9.yml @@ -24,7 +24,6 @@ initialState: finalState: documentContents: |- begin - ensure a = 10 end diff --git a/data/fixtures/recorded/languages/rust/chuckFunkMade.yml b/data/fixtures/recorded/languages/rust/chuckFunkMade.yml index 5ea043b8a8..c7abe56233 100644 --- a/data/fixtures/recorded/languages/rust/chuckFunkMade.yml +++ b/data/fixtures/recorded/languages/rust/chuckFunkMade.yml @@ -24,8 +24,7 @@ initialState: start: {line: 0, character: 3} end: {line: 0, character: 7} finalState: - documentContents: |+ - + documentContents: "" selections: - - anchor: {line: 1, character: 0} - active: {line: 1, character: 0} + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} diff --git a/data/fixtures/recorded/languages/rust/chuckState.yml b/data/fixtures/recorded/languages/rust/chuckState.yml index 059386d0c1..a96a9a220e 100644 --- a/data/fixtures/recorded/languages/rust/chuckState.yml +++ b/data/fixtures/recorded/languages/rust/chuckState.yml @@ -18,8 +18,7 @@ initialState: active: {line: 0, character: 10} marks: {} finalState: - documentContents: |+ - + documentContents: "" selections: - anchor: {line: 0, character: 0} active: {line: 0, character: 0} diff --git a/data/fixtures/recorded/languages/rust/chuckTypeAir.yml b/data/fixtures/recorded/languages/rust/chuckTypeAir.yml index 0f7525995a..ac06f872ba 100644 --- a/data/fixtures/recorded/languages/rust/chuckTypeAir.yml +++ b/data/fixtures/recorded/languages/rust/chuckTypeAir.yml @@ -31,13 +31,11 @@ initialState: end: {line: 0, character: 5} finalState: documentContents: | - - impl T for Option { fn f() { unimplemented!() } } selections: - - anchor: {line: 6, character: 0} - active: {line: 6, character: 0} + - anchor: {line: 4, character: 0} + active: {line: 4, character: 0} diff --git a/data/fixtures/recorded/languages/rust/chuckTypeMade.yml b/data/fixtures/recorded/languages/rust/chuckTypeMade.yml index 4434f7ed22..afedfe833a 100644 --- a/data/fixtures/recorded/languages/rust/chuckTypeMade.yml +++ b/data/fixtures/recorded/languages/rust/chuckTypeMade.yml @@ -30,12 +30,10 @@ initialState: start: {line: 4, character: 0} end: {line: 4, character: 4} finalState: - documentContents: |+ + documentContents: | trait T { fn f(); } - - selections: - - anchor: {line: 4, character: 0} - active: {line: 4, character: 0} + - anchor: {line: 3, character: 0} + active: {line: 3, character: 0} diff --git a/data/fixtures/recorded/languages/scala/chuckBranchSun.yml b/data/fixtures/recorded/languages/scala/chuckBranchSun.yml index 2680719d18..3e5501fd08 100644 --- a/data/fixtures/recorded/languages/scala/chuckBranchSun.yml +++ b/data/fixtures/recorded/languages/scala/chuckBranchSun.yml @@ -30,10 +30,9 @@ finalState: documentContents: | def matchTest(x: Int): String = x match { case 0 => "zero" - case 2 => "two" case _ => "other" } selections: - - anchor: {line: 3, character: 2} - active: {line: 4, character: 2} + - anchor: {line: 2, character: 2} + active: {line: 3, character: 2} diff --git a/data/fixtures/recorded/languages/scss/chuckState2.yml b/data/fixtures/recorded/languages/scss/chuckState2.yml index 378da9f7af..8572d150ac 100644 --- a/data/fixtures/recorded/languages/scss/chuckState2.yml +++ b/data/fixtures/recorded/languages/scss/chuckState2.yml @@ -22,8 +22,7 @@ initialState: active: {line: 0, character: 4} marks: {} finalState: - documentContents: |+ - + documentContents: "" selections: - anchor: {line: 0, character: 0} active: {line: 0, character: 0} diff --git a/data/fixtures/recorded/languages/typescript/chuckState.yml b/data/fixtures/recorded/languages/typescript/chuckState.yml index d9c5bb6d90..92646043b9 100644 --- a/data/fixtures/recorded/languages/typescript/chuckState.yml +++ b/data/fixtures/recorded/languages/typescript/chuckState.yml @@ -23,7 +23,6 @@ initialState: finalState: documentContents: |- interface Foo { - baz: Baz; } selections: diff --git a/data/fixtures/recorded/languages/typescript/chuckState2.yml b/data/fixtures/recorded/languages/typescript/chuckState2.yml index 87e740df06..b2f0559f99 100644 --- a/data/fixtures/recorded/languages/typescript/chuckState2.yml +++ b/data/fixtures/recorded/languages/typescript/chuckState2.yml @@ -22,7 +22,6 @@ initialState: finalState: documentContents: |- class Foo { - } selections: - anchor: {line: 1, character: 0} diff --git a/data/fixtures/recorded/languages/typescript/ditchFunk.yml b/data/fixtures/recorded/languages/typescript/ditchFunk.yml index bbcb261b33..8d7d4350c3 100644 --- a/data/fixtures/recorded/languages/typescript/ditchFunk.yml +++ b/data/fixtures/recorded/languages/typescript/ditchFunk.yml @@ -27,7 +27,6 @@ finalState: abstract class Foo { protected abstract bar(): void; - baz() {} } selections: diff --git a/data/fixtures/recorded/languages/typescript/ditchFunk2.yml b/data/fixtures/recorded/languages/typescript/ditchFunk2.yml index 67d05701bc..26c6adc186 100644 --- a/data/fixtures/recorded/languages/typescript/ditchFunk2.yml +++ b/data/fixtures/recorded/languages/typescript/ditchFunk2.yml @@ -22,7 +22,6 @@ initialState: finalState: documentContents: |- abstract class Foo { - } selections: - anchor: {line: 1, character: 0} diff --git a/data/fixtures/recorded/languages/yaml/chuckItem11.yml b/data/fixtures/recorded/languages/yaml/chuckItem11.yml index 213243ad42..09b462c22b 100644 --- a/data/fixtures/recorded/languages/yaml/chuckItem11.yml +++ b/data/fixtures/recorded/languages/yaml/chuckItem11.yml @@ -19,8 +19,7 @@ initialState: active: {line: 1, character: 2} marks: {} finalState: - documentContents: | - foo: + documentContents: "foo:" selections: - - anchor: {line: 1, character: 0} - active: {line: 1, character: 0} + - anchor: {line: 0, character: 4} + active: {line: 0, character: 4} diff --git a/data/fixtures/scopes/c/class.scope b/data/fixtures/scopes/c/class.scope index 9daca1d239..8888978407 100644 --- a/data/fixtures/scopes/c/class.scope +++ b/data/fixtures/scopes/c/class.scope @@ -8,54 +8,84 @@ typedef enum { jjj, kkk } lll; --- [#1 Content] = -[#1 Removal] = [#1 Domain] = 0:0-0:24 >------------------------< 0| struct aaa { int bbb; }; +[#1 Removal] = 0:0-1:0 + >------------------------ +0| struct aaa { int bbb; }; +1| union bbb { int ccc; }; + < + [#1 Insertion delimiter] = "\n\n" [#2 Content] = -[#2 Removal] = [#2 Domain] = 1:0-1:23 >-----------------------< 1| union bbb { int ccc; }; +[#2 Removal] = 1:0-2:0 + >----------------------- +1| union bbb { int ccc; }; +2| enum ccc { ddd, eee }; + < + [#2 Insertion delimiter] = "\n\n" [#3 Content] = -[#3 Removal] = [#3 Domain] = 2:0-2:22 >----------------------< 2| enum ccc { ddd, eee }; +[#3 Removal] = 2:0-3:0 + >---------------------- +2| enum ccc { ddd, eee }; +3| + < + [#3 Insertion delimiter] = "\n\n" [#4 Content] = -[#4 Removal] = [#4 Domain] = 4:0-4:32 >--------------------------------< 4| typedef struct { int fff; } ggg; +[#4 Removal] = 4:0-5:0 + >-------------------------------- +4| typedef struct { int fff; } ggg; +5| typedef union { int hhh; } iii; + < + [#4 Insertion delimiter] = "\n\n" [#5 Content] = -[#5 Removal] = [#5 Domain] = 5:0-5:31 >-------------------------------< 5| typedef union { int hhh; } iii; +[#5 Removal] = 5:0-6:0 + >------------------------------- +5| typedef union { int hhh; } iii; +6| typedef enum { jjj, kkk } lll; + < + [#5 Insertion delimiter] = "\n\n" [#6 Content] = -[#6 Removal] = [#6 Domain] = 6:0-6:30 >------------------------------< 6| typedef enum { jjj, kkk } lll; +[#6 Removal] = 5:31-6:30 + > +5| typedef union { int hhh; } iii; +6| typedef enum { jjj, kkk } lll; + ------------------------------< + [#6 Insertion delimiter] = "\n\n" diff --git a/data/fixtures/scopes/c/ifStatement.scope b/data/fixtures/scopes/c/ifStatement.scope index 57b5634c53..67460b075d 100644 --- a/data/fixtures/scopes/c/ifStatement.scope +++ b/data/fixtures/scopes/c/ifStatement.scope @@ -8,9 +8,11 @@ void func() { >-------------< 1| if (true) { } -[Removal] = 1:0-1:17 - >-----------------< +[Removal] = 1:0-2:0 + >----------------- 1| if (true) { } +2| } + < [Leading delimiter] = 1:0-1:4 >----< diff --git a/data/fixtures/scopes/c/statement.class.scope b/data/fixtures/scopes/c/statement.class.scope index e71bacf73a..74ab361834 100644 --- a/data/fixtures/scopes/c/statement.class.scope +++ b/data/fixtures/scopes/c/statement.class.scope @@ -8,54 +8,84 @@ typedef enum { jjj, kkk } lll; --- [#1 Content] = -[#1 Removal] = [#1 Domain] = 0:0-0:24 >------------------------< 0| struct aaa { int bbb; }; +[#1 Removal] = 0:0-1:0 + >------------------------ +0| struct aaa { int bbb; }; +1| union bbb { int ccc; }; + < + [#1 Insertion delimiter] = "\n" [#2 Content] = -[#2 Removal] = [#2 Domain] = 1:0-1:23 >-----------------------< 1| union bbb { int ccc; }; +[#2 Removal] = 1:0-2:0 + >----------------------- +1| union bbb { int ccc; }; +2| enum ccc { ddd, eee }; + < + [#2 Insertion delimiter] = "\n" [#3 Content] = -[#3 Removal] = [#3 Domain] = 2:0-2:22 >----------------------< 2| enum ccc { ddd, eee }; +[#3 Removal] = 2:0-3:0 + >---------------------- +2| enum ccc { ddd, eee }; +3| + < + [#3 Insertion delimiter] = "\n" [#4 Content] = -[#4 Removal] = [#4 Domain] = 4:0-4:32 >--------------------------------< 4| typedef struct { int fff; } ggg; +[#4 Removal] = 4:0-5:0 + >-------------------------------- +4| typedef struct { int fff; } ggg; +5| typedef union { int hhh; } iii; + < + [#4 Insertion delimiter] = "\n" [#5 Content] = -[#5 Removal] = [#5 Domain] = 5:0-5:31 >-------------------------------< 5| typedef union { int hhh; } iii; +[#5 Removal] = 5:0-6:0 + >------------------------------- +5| typedef union { int hhh; } iii; +6| typedef enum { jjj, kkk } lll; + < + [#5 Insertion delimiter] = "\n" [#6 Content] = -[#6 Removal] = [#6 Domain] = 6:0-6:30 >------------------------------< 6| typedef enum { jjj, kkk } lll; +[#6 Removal] = 5:31-6:30 + > +5| typedef union { int hhh; } iii; +6| typedef enum { jjj, kkk } lll; + ------------------------------< + [#6 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/c/type.class.scope b/data/fixtures/scopes/c/type.class.scope index 85f0b19848..60c5a84c99 100644 --- a/data/fixtures/scopes/c/type.class.scope +++ b/data/fixtures/scopes/c/type.class.scope @@ -8,54 +8,84 @@ typedef enum {} lll; --- [#1 Content] = -[#1 Removal] = [#1 Domain] = 0:0-0:14 >--------------< 0| struct aaa {}; +[#1 Removal] = 0:0-1:0 + >-------------- +0| struct aaa {}; +1| union bbb {}; + < + [#1 Insertion delimiter] = " " [#2 Content] = -[#2 Removal] = [#2 Domain] = 1:0-1:13 >-------------< 1| union bbb {}; +[#2 Removal] = 1:0-2:0 + >------------- +1| union bbb {}; +2| enum ccc {}; + < + [#2 Insertion delimiter] = " " [#3 Content] = -[#3 Removal] = [#3 Domain] = 2:0-2:12 >------------< 2| enum ccc {}; +[#3 Removal] = 2:0-3:0 + >------------ +2| enum ccc {}; +3| + < + [#3 Insertion delimiter] = " " [#4 Content] = -[#4 Removal] = [#4 Domain] = 4:0-4:22 >----------------------< 4| typedef struct {} ggg; +[#4 Removal] = 4:0-5:0 + >---------------------- +4| typedef struct {} ggg; +5| typedef union {} iii; + < + [#4 Insertion delimiter] = " " [#5 Content] = -[#5 Removal] = [#5 Domain] = 5:0-5:21 >---------------------< 5| typedef union {} iii; +[#5 Removal] = 5:0-6:0 + >--------------------- +5| typedef union {} iii; +6| typedef enum {} lll; + < + [#5 Insertion delimiter] = " " [#6 Content] = -[#6 Removal] = [#6 Domain] = 6:0-6:20 >--------------------< 6| typedef enum {} lll; +[#6 Removal] = 5:21-6:20 + > +5| typedef union {} iii; +6| typedef enum {} lll; + --------------------< + [#6 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/cpp/class.scope b/data/fixtures/scopes/cpp/class.scope index 18d719b8b9..c0d93c7ae9 100644 --- a/data/fixtures/scopes/cpp/class.scope +++ b/data/fixtures/scopes/cpp/class.scope @@ -3,18 +3,28 @@ enum class ccc { ddd, eee }; --- [#1 Content] = -[#1 Removal] = [#1 Domain] = 0:0-0:23 >-----------------------< 0| class aaa { int bbb; }; +[#1 Removal] = 0:0-1:0 + >----------------------- +0| class aaa { int bbb; }; +1| enum class ccc { ddd, eee }; + < + [#1 Insertion delimiter] = "\n\n" [#2 Content] = -[#2 Removal] = [#2 Domain] = 1:0-1:28 >----------------------------< 1| enum class ccc { ddd, eee }; +[#2 Removal] = 0:23-1:28 + > +0| class aaa { int bbb; }; +1| enum class ccc { ddd, eee }; + ----------------------------< + [#2 Insertion delimiter] = "\n\n" diff --git a/data/fixtures/scopes/cpp/ifStatement.scope b/data/fixtures/scopes/cpp/ifStatement.scope index 59f601f63e..f98039aae3 100644 --- a/data/fixtures/scopes/cpp/ifStatement.scope +++ b/data/fixtures/scopes/cpp/ifStatement.scope @@ -8,9 +8,11 @@ void funk() { >----------------------< 1| if constexpr (true) {} -[Removal] = 1:0-1:26 - >--------------------------< +[Removal] = 1:0-2:0 + >-------------------------- 1| if constexpr (true) {} +2| } + < [Leading delimiter] = 1:0-1:4 >----< diff --git a/data/fixtures/scopes/cpp/statement.class.scope b/data/fixtures/scopes/cpp/statement.class.scope index f87c495b07..ee2f153e94 100644 --- a/data/fixtures/scopes/cpp/statement.class.scope +++ b/data/fixtures/scopes/cpp/statement.class.scope @@ -3,18 +3,28 @@ enum class ccc { ddd, eee }; --- [#1 Content] = -[#1 Removal] = [#1 Domain] = 0:0-0:23 >-----------------------< 0| class aaa { int bbb; }; +[#1 Removal] = 0:0-1:0 + >----------------------- +0| class aaa { int bbb; }; +1| enum class ccc { ddd, eee }; + < + [#1 Insertion delimiter] = "\n" [#2 Content] = -[#2 Removal] = [#2 Domain] = 1:0-1:28 >----------------------------< 1| enum class ccc { ddd, eee }; +[#2 Removal] = 0:23-1:28 + > +0| class aaa { int bbb; }; +1| enum class ccc { ddd, eee }; + ----------------------------< + [#2 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/cpp/type.class.scope b/data/fixtures/scopes/cpp/type.class.scope index fbefdcd092..c8bcfb07c9 100644 --- a/data/fixtures/scopes/cpp/type.class.scope +++ b/data/fixtures/scopes/cpp/type.class.scope @@ -3,11 +3,16 @@ enum class ccc { ddd, eee }; --- [#1 Content] = -[#1 Removal] = [#1 Domain] = 0:0-0:23 >-----------------------< 0| class aaa { int bbb; }; +[#1 Removal] = 0:0-1:0 + >----------------------- +0| class aaa { int bbb; }; +1| enum class ccc { ddd, eee }; + < + [#1 Insertion delimiter] = " " @@ -35,9 +40,14 @@ enum class ccc { ddd, eee }; [#3 Content] = -[#3 Removal] = [#3 Domain] = 1:0-1:28 >----------------------------< 1| enum class ccc { ddd, eee }; +[#3 Removal] = 0:23-1:28 + > +0| class aaa { int bbb; }; +1| enum class ccc { ddd, eee }; + ----------------------------< + [#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/csharp/namedFunction.constructor.scope b/data/fixtures/scopes/csharp/namedFunction.constructor.scope index acf3cc514f..e523d2c5b5 100644 --- a/data/fixtures/scopes/csharp/namedFunction.constructor.scope +++ b/data/fixtures/scopes/csharp/namedFunction.constructor.scope @@ -8,9 +8,11 @@ class Program { >--------------------< 1| public Program() { } -[Removal] = 1:0-1:24 - >------------------------< +[Removal] = 1:0-2:0 + >------------------------ 1| public Program() { } +2| } + < [Leading delimiter] = 1:0-1:4 >----< diff --git a/data/fixtures/scopes/csharp/namedFunction.method.scope b/data/fixtures/scopes/csharp/namedFunction.method.scope index 3281c0b960..6b0f6d705b 100644 --- a/data/fixtures/scopes/csharp/namedFunction.method.scope +++ b/data/fixtures/scopes/csharp/namedFunction.method.scope @@ -8,9 +8,11 @@ class Program { >---------------------< 1| public void foo() { } -[Removal] = 1:0-1:25 - >-------------------------< +[Removal] = 1:0-2:0 + >------------------------- 1| public void foo() { } +2| } + < [Leading delimiter] = 1:0-1:4 >----< diff --git a/data/fixtures/scopes/dart/ifStatement.scope b/data/fixtures/scopes/dart/ifStatement.scope index 09ee23aab9..dbda11f63d 100644 --- a/data/fixtures/scopes/dart/ifStatement.scope +++ b/data/fixtures/scopes/dart/ifStatement.scope @@ -8,9 +8,11 @@ foo() { >-------------< 1| if (true) { } -[Removal] = 1:0-1:15 - >---------------< +[Removal] = 1:0-2:0 + >--------------- 1| if (true) { } +2| } + < [Leading delimiter] = 1:0-1:2 >--< diff --git a/data/fixtures/scopes/java/branch.if.scope b/data/fixtures/scopes/java/branch.if.scope index 64c8edf762..8bf55324af 100644 --- a/data/fixtures/scopes/java/branch.if.scope +++ b/data/fixtures/scopes/java/branch.if.scope @@ -18,18 +18,28 @@ else {} [#2 Content] = -[#2 Removal] = [#2 Domain] = 1:0-1:18 >------------------< 1| else if (false) {} +[#2 Removal] = 1:0-2:0 + >------------------ +1| else if (false) {} +2| else {} + < + [#2 Insertion delimiter] = "\n" [#3 Content] = -[#3 Removal] = [#3 Domain] = 2:0-2:7 >-------< 2| else {} +[#3 Removal] = 1:18-2:7 + > +1| else if (false) {} +2| else {} + -------< + [#3 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/java/branch.try.scope b/data/fixtures/scopes/java/branch.try.scope index 19049b7bd1..5da5630e30 100644 --- a/data/fixtures/scopes/java/branch.try.scope +++ b/data/fixtures/scopes/java/branch.try.scope @@ -4,27 +4,42 @@ finally {} --- [#1 Content] = -[#1 Removal] = [#1 Domain] = 0:0-0:6 >------< 0| try {} +[#1 Removal] = 0:0-1:0 + >------ +0| try {} +1| catch(Exception e) {} + < + [#1 Insertion delimiter] = "\n" [#2 Content] = -[#2 Removal] = [#2 Domain] = 1:0-1:21 >---------------------< 1| catch(Exception e) {} +[#2 Removal] = 1:0-2:0 + >--------------------- +1| catch(Exception e) {} +2| finally {} + < + [#2 Insertion delimiter] = "\n" [#3 Content] = -[#3 Removal] = [#3 Domain] = 2:0-2:10 >----------< 2| finally {} +[#3 Removal] = 1:21-2:10 + > +1| catch(Exception e) {} +2| finally {} + ----------< + [#3 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/java/collectionItem.unenclosed2.scope b/data/fixtures/scopes/java/collectionItem.unenclosed2.scope index ccc7682a58..93021c3c80 100644 --- a/data/fixtures/scopes/java/collectionItem.unenclosed2.scope +++ b/data/fixtures/scopes/java/collectionItem.unenclosed2.scope @@ -13,12 +13,13 @@ public class MyClass { 3| } -----< -[#1 Removal] = 1:0-3:5 +[#1 Removal] = 1:0-4:0 >-------------------------- 1| public void myFunk() { 2| String foo, bar; 3| } - -----< +4| } + < [#1 Leading delimiter] = 1:0-1:4 >----< diff --git a/data/fixtures/scopes/javascript.core/branch.if.scope b/data/fixtures/scopes/javascript.core/branch.if.scope index 6202480fc7..2b551be537 100644 --- a/data/fixtures/scopes/javascript.core/branch.if.scope +++ b/data/fixtures/scopes/javascript.core/branch.if.scope @@ -29,7 +29,6 @@ else { [#2 Content] = -[#2 Removal] = [#2 Domain] = 3:0-5:1 >----------------- 3| else if (false) { @@ -37,11 +36,18 @@ else { 5| } -< +[#2 Removal] = 3:0-6:0 + >----------------- +3| else if (false) { +4| +5| } +6| else { + < + [#2 Insertion delimiter] = "\n" [#3 Content] = -[#3 Removal] = [#3 Domain] = 6:0-8:1 >------ 6| else { @@ -49,4 +55,12 @@ else { 8| } -< +[#3 Removal] = 5:1-8:1 + > +5| } +6| else { +7| +8| } + -< + [#3 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/javascript.core/branch.switchCase.scope b/data/fixtures/scopes/javascript.core/branch.switchCase.scope index b13746d799..e663cdd925 100644 --- a/data/fixtures/scopes/javascript.core/branch.switchCase.scope +++ b/data/fixtures/scopes/javascript.core/branch.switchCase.scope @@ -9,9 +9,11 @@ switch (value) { >-----------< 1| case 0: { } -[#1 Removal] = 1:0-1:13 - >-------------< +[#1 Removal] = 1:0-2:0 + >------------- 1| case 0: { } +2| default: { } + < [#1 Leading delimiter] = 1:0-1:2 >--< @@ -25,9 +27,11 @@ switch (value) { >------------< 2| default: { } -[#2 Removal] = 2:0-2:14 - >--------------< +[#2 Removal] = 2:0-3:0 + >-------------- 2| default: { } +3| } + < [#2 Leading delimiter] = 2:0-2:2 >--< diff --git a/data/fixtures/scopes/javascript.core/branch.try.scope b/data/fixtures/scopes/javascript.core/branch.try.scope index 95896234b1..ea74af16e4 100644 --- a/data/fixtures/scopes/javascript.core/branch.try.scope +++ b/data/fixtures/scopes/javascript.core/branch.try.scope @@ -10,7 +10,6 @@ finally { --- [#1 Content] = -[#1 Removal] = [#1 Domain] = 0:0-2:1 >----- 0| try { @@ -18,11 +17,18 @@ finally { 2| } -< +[#1 Removal] = 0:0-3:0 + >----- +0| try { +1| +2| } +3| catch(error) { + < + [#1 Insertion delimiter] = "\n" [#2 Content] = -[#2 Removal] = [#2 Domain] = 3:0-5:1 >-------------- 3| catch(error) { @@ -30,11 +36,18 @@ finally { 5| } -< +[#2 Removal] = 3:0-6:0 + >-------------- +3| catch(error) { +4| +5| } +6| finally { + < + [#2 Insertion delimiter] = "\n" [#3 Content] = -[#3 Removal] = [#3 Domain] = 6:0-8:1 >--------- 6| finally { @@ -42,4 +55,12 @@ finally { 8| } -< +[#3 Removal] = 5:1-8:1 + > +5| } +6| finally { +7| +8| } + -< + [#3 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/javascript.core/namedFunction.constructor.scope b/data/fixtures/scopes/javascript.core/namedFunction.constructor.scope index 430b75305b..25cdced0f6 100644 --- a/data/fixtures/scopes/javascript.core/namedFunction.constructor.scope +++ b/data/fixtures/scopes/javascript.core/namedFunction.constructor.scope @@ -8,9 +8,11 @@ class MyClass { >-----------------< 1| constructor() { } -[Removal] = 1:0-1:19 - >-------------------< +[Removal] = 1:0-2:0 + >------------------- 1| constructor() { } +2| } + < [Leading delimiter] = 1:0-1:2 >--< diff --git a/data/fixtures/scopes/javascript.core/namedFunction.method.scope b/data/fixtures/scopes/javascript.core/namedFunction.method.scope index f269a30a5c..b926badbbb 100644 --- a/data/fixtures/scopes/javascript.core/namedFunction.method.scope +++ b/data/fixtures/scopes/javascript.core/namedFunction.method.scope @@ -8,9 +8,11 @@ class MyClass { >------------< 1| myFunk() { } -[Removal] = 1:0-1:14 - >--------------< +[Removal] = 1:0-2:0 + >-------------- 1| myFunk() { } +2| } + < [Leading delimiter] = 1:0-1:2 >--< diff --git a/data/fixtures/scopes/jsonl/map.scope b/data/fixtures/scopes/jsonl/map.scope index bd1d2fc584..46c7892ac0 100644 --- a/data/fixtures/scopes/jsonl/map.scope +++ b/data/fixtures/scopes/jsonl/map.scope @@ -3,18 +3,28 @@ --- [#1 Content] = -[#1 Removal] = [#1 Domain] = 0:0-0:10 >----------< 0| {"aaa": 0} +[#1 Removal] = 0:0-1:0 + >---------- +0| {"aaa": 0} +1| {"bbb": 0} + < + [#1 Insertion delimiter] = " " [#2 Content] = -[#2 Removal] = [#2 Domain] = 1:0-1:10 >----------< 1| {"bbb": 0} +[#2 Removal] = 0:10-1:10 + > +0| {"aaa": 0} +1| {"bbb": 0} + ----------< + [#2 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/latex/endTag.scope b/data/fixtures/scopes/latex/endTag.scope index 30d7492f81..2c5db50e7b 100644 --- a/data/fixtures/scopes/latex/endTag.scope +++ b/data/fixtures/scopes/latex/endTag.scope @@ -3,11 +3,16 @@ \end{quote} --- -[Content] = -[Removal] = 2:0-2:11 +[Content] = 2:0-2:11 >-----------< 2| \end{quote} +[Removal] = 1:9-2:11 + > +1| Hello +2| \end{quote} + -----------< + [Domain] = 0:0-2:11 >------------- 0| \begin{quote} diff --git a/data/fixtures/scopes/latex/startTag.scope b/data/fixtures/scopes/latex/startTag.scope index e93798776d..e429ab9e96 100644 --- a/data/fixtures/scopes/latex/startTag.scope +++ b/data/fixtures/scopes/latex/startTag.scope @@ -3,11 +3,16 @@ \end{quote} --- -[Content] = -[Removal] = 0:0-0:13 +[Content] = 0:0-0:13 >-------------< 0| \begin{quote} +[Removal] = 0:0-1:0 + >------------- +0| \begin{quote} +1| Hello + < + [Domain] = 0:0-2:11 >------------- 0| \begin{quote} diff --git a/data/fixtures/scopes/latex/tags.scope b/data/fixtures/scopes/latex/tags.scope index f30896d8ac..43eb2a03b0 100644 --- a/data/fixtures/scopes/latex/tags.scope +++ b/data/fixtures/scopes/latex/tags.scope @@ -3,18 +3,28 @@ \end{quote} --- -[.1 Content] = -[.1 Removal] = 0:0-0:13 +[.1 Content] = 0:0-0:13 >-------------< 0| \begin{quote} +[.1 Removal] = 0:0-1:0 + >------------- +0| \begin{quote} +1| Hello + < + [.1 Insertion delimiter] = " " -[.2 Content] = -[.2 Removal] = 2:0-2:11 +[.2 Content] = 2:0-2:11 >-----------< 2| \end{quote} +[.2 Removal] = 1:9-2:11 + > +1| Hello +2| \end{quote} + -----------< + [.2 Insertion delimiter] = " " [Domain] = 0:0-2:11 diff --git a/data/fixtures/scopes/lua/branch.if.scope b/data/fixtures/scopes/lua/branch.if.scope index 20e001180e..606863122e 100644 --- a/data/fixtures/scopes/lua/branch.if.scope +++ b/data/fixtures/scopes/lua/branch.if.scope @@ -8,13 +8,19 @@ end --- [#1 Content] = -[#1 Removal] = [#1 Domain] = 0:0-1:29 >------------- 0| if x < y then 1| print("x is less than y") -----------------------------< +[#1 Removal] = 0:0-2:0 + >------------- +0| if x < y then +1| print("x is less than y") +2| elseif x > y then + < + [#1 Interior] = 1:4-1:29 >-------------------------< 1| print("x is less than y") @@ -23,13 +29,19 @@ end [#2 Content] = -[#2 Removal] = [#2 Domain] = 2:0-3:32 >----------------- 2| elseif x > y then 3| print("x is greater than y") --------------------------------< +[#2 Removal] = 2:0-4:0 + >----------------- +2| elseif x > y then +3| print("x is greater than y") +4| else + < + [#2 Interior] = 3:4-3:32 >----------------------------< 3| print("x is greater than y") @@ -38,13 +50,19 @@ end [#3 Content] = -[#3 Removal] = [#3 Domain] = 4:0-5:28 >---- 4| else 5| print("x is equal to y") ----------------------------< +[#3 Removal] = 4:0-6:0 + >---- +4| else +5| print("x is equal to y") +6| end + < + [#3 Interior] = 5:4-5:28 >------------------------< 5| print("x is equal to y") diff --git a/data/fixtures/scopes/markdown/collectionItem.unenclosed.scope b/data/fixtures/scopes/markdown/collectionItem.unenclosed.scope index 4fe3448bd7..334572988c 100644 --- a/data/fixtures/scopes/markdown/collectionItem.unenclosed.scope +++ b/data/fixtures/scopes/markdown/collectionItem.unenclosed.scope @@ -35,9 +35,11 @@ >-----------------------------------< 1| - This is the second level of a list. -[#2 Removal] = 1:0-1:39 - >---------------------------------------< +[#2 Removal] = 1:0-2:0 + >--------------------------------------- 1| - This is the second level of a list. +2| - This is the first level of a list again. + < [#2 Leading delimiter] = 1:0-1:2 >--< diff --git a/data/fixtures/scopes/markdown/notebookCell.scope b/data/fixtures/scopes/markdown/notebookCell.scope index bc17667883..60b0eb34be 100644 --- a/data/fixtures/scopes/markdown/notebookCell.scope +++ b/data/fixtures/scopes/markdown/notebookCell.scope @@ -10,7 +10,6 @@ hello --- [#1 Content] = -[#1 Removal] = [#1 Domain] = 0:0-3:3 >--------- 0| ```python @@ -19,6 +18,16 @@ hello 3| ``` ---< +[#1 Removal] = 0:0-5:0 + >--------- +0| ```python +1| def foo(): +2| pass +3| ``` +4| +5| ``` + < + [#1 Interior: Content] = 1:0-2:8 >---------- 1| def foo(): @@ -36,7 +45,6 @@ hello [#2 Content] = -[#2 Removal] = [#2 Domain] = 5:0-7:3 >--- 5| ``` @@ -44,6 +52,15 @@ hello 7| ``` ---< +[#2 Removal] = 4:0-8:0 + > +4| +5| ``` +6| hello +7| ``` +8| + < + [#2 Interior: Content] = 6:0-6:5 >-----< 6| hello diff --git a/data/fixtures/scopes/php/comment.block.scope b/data/fixtures/scopes/php/comment.block.scope index 5409f7310e..698d2b61d0 100644 --- a/data/fixtures/scopes/php/comment.block.scope +++ b/data/fixtures/scopes/php/comment.block.scope @@ -8,9 +8,11 @@ >------------------< 1| /* Hello world! */ -[Removal] = 1:0-1:22 - >----------------------< +[Removal] = 1:0-2:0 + >---------------------- 1| /* Hello world! */ +2| ?> + < [Leading delimiter] = 1:0-1:4 >----< diff --git a/data/fixtures/scopes/php/comment.line.scope b/data/fixtures/scopes/php/comment.line.scope index f1c8e91510..176dba0c12 100644 --- a/data/fixtures/scopes/php/comment.line.scope +++ b/data/fixtures/scopes/php/comment.line.scope @@ -8,9 +8,11 @@ >---------------< 1| // Hello world! -[Removal] = 1:0-1:19 - >-------------------< +[Removal] = 1:0-2:0 + >------------------- 1| // Hello world! +2| ?> + < [Leading delimiter] = 1:0-1:4 >----< diff --git a/data/fixtures/scopes/php/comment.line2.scope b/data/fixtures/scopes/php/comment.line2.scope index fb0827d753..5e861b52cb 100644 --- a/data/fixtures/scopes/php/comment.line2.scope +++ b/data/fixtures/scopes/php/comment.line2.scope @@ -8,9 +8,11 @@ >--------------< 1| # Hello world! -[Removal] = 1:0-1:18 - >------------------< +[Removal] = 1:0-2:0 + >------------------ 1| # Hello world! +2| ?> + < [Leading delimiter] = 1:0-1:4 >----< diff --git a/data/fixtures/scopes/python/branch.if.scope b/data/fixtures/scopes/python/branch.if.scope index def93d3f12..64926e37fe 100644 --- a/data/fixtures/scopes/python/branch.if.scope +++ b/data/fixtures/scopes/python/branch.if.scope @@ -7,33 +7,51 @@ else: --- [#1 Content] = -[#1 Removal] = [#1 Domain] = 0:0-1:8 >-------- 0| if True: 1| pass --------< +[#1 Removal] = 0:0-2:0 + >-------- +0| if True: +1| pass +2| elif False: + < + [#1 Insertion delimiter] = "\n" [#2 Content] = -[#2 Removal] = [#2 Domain] = 2:0-3:8 >----------- 2| elif False: 3| pass --------< +[#2 Removal] = 2:0-4:0 + >----------- +2| elif False: +3| pass +4| else: + < + [#2 Insertion delimiter] = "\n" [#3 Content] = -[#3 Removal] = [#3 Domain] = 4:0-5:8 >----- 4| else: 5| pass --------< +[#3 Removal] = 3:8-5:8 + > +3| pass +4| else: +5| pass + --------< + [#3 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/python/branch.loop.scope b/data/fixtures/scopes/python/branch.loop.scope index 41ab3b4189..eb3c4708b2 100644 --- a/data/fixtures/scopes/python/branch.loop.scope +++ b/data/fixtures/scopes/python/branch.loop.scope @@ -5,22 +5,34 @@ else: --- [#1 Content] = -[#1 Removal] = [#1 Domain] = 0:0-1:8 >----------- 0| while True: 1| pass --------< +[#1 Removal] = 0:0-2:0 + >----------- +0| while True: +1| pass +2| else: + < + [#1 Insertion delimiter] = "\n" [#2 Content] = -[#2 Removal] = [#2 Domain] = 2:0-3:8 >----- 2| else: 3| pass --------< +[#2 Removal] = 1:8-3:8 + > +1| pass +2| else: +3| pass + --------< + [#2 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/python/branch.loop2.scope b/data/fixtures/scopes/python/branch.loop2.scope index bedbee310d..39b2df2d04 100644 --- a/data/fixtures/scopes/python/branch.loop2.scope +++ b/data/fixtures/scopes/python/branch.loop2.scope @@ -5,22 +5,34 @@ else: --- [#1 Content] = -[#1 Removal] = [#1 Domain] = 0:0-1:8 >--------------- 0| for aaa in bbb: 1| pass --------< +[#1 Removal] = 0:0-2:0 + >--------------- +0| for aaa in bbb: +1| pass +2| else: + < + [#1 Insertion delimiter] = "\n" [#2 Content] = -[#2 Removal] = [#2 Domain] = 2:0-3:8 >----- 2| else: 3| pass --------< +[#2 Removal] = 1:8-3:8 + > +1| pass +2| else: +3| pass + --------< + [#2 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/python/branch.switchCase.scope b/data/fixtures/scopes/python/branch.switchCase.scope index 51160cd9ce..5a95cd0f28 100644 --- a/data/fixtures/scopes/python/branch.switchCase.scope +++ b/data/fixtures/scopes/python/branch.switchCase.scope @@ -12,11 +12,12 @@ match 0: 2| pass ------------< -[#1 Removal] = 1:0-2:12 +[#1 Removal] = 1:0-3:0 >------------- 1| case [0]: 2| pass - ------------< +3| case [1]: + < [#1 Leading delimiter] = 1:0-1:4 >----< @@ -32,8 +33,9 @@ match 0: 4| pass ------------< -[#2 Removal] = 3:0-4:12 - >------------- +[#2 Removal] = 2:12-4:12 + > +2| pass 3| case [1]: 4| pass ------------< diff --git a/data/fixtures/scopes/python/branch.try.scope b/data/fixtures/scopes/python/branch.try.scope index fb9f51e4ab..a17648dcf7 100644 --- a/data/fixtures/scopes/python/branch.try.scope +++ b/data/fixtures/scopes/python/branch.try.scope @@ -7,33 +7,51 @@ finally: --- [#1 Content] = -[#1 Removal] = [#1 Domain] = 0:0-1:8 >---- 0| try: 1| pass --------< +[#1 Removal] = 0:0-2:0 + >---- +0| try: +1| pass +2| except: + < + [#1 Insertion delimiter] = "\n" [#2 Content] = -[#2 Removal] = [#2 Domain] = 2:0-3:8 >------- 2| except: 3| pass --------< +[#2 Removal] = 2:0-4:0 + >------- +2| except: +3| pass +4| finally: + < + [#2 Insertion delimiter] = "\n" [#3 Content] = -[#3 Removal] = [#3 Domain] = 4:0-5:8 >-------- 4| finally: 5| pass --------< +[#3 Removal] = 3:8-5:8 + > +3| pass +4| finally: +5| pass + --------< + [#3 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/python/branch.try2.scope b/data/fixtures/scopes/python/branch.try2.scope index 7469d260a3..821983af5b 100644 --- a/data/fixtures/scopes/python/branch.try2.scope +++ b/data/fixtures/scopes/python/branch.try2.scope @@ -7,33 +7,51 @@ else: --- [#1 Content] = -[#1 Removal] = [#1 Domain] = 0:0-1:8 >---- 0| try: 1| pass --------< +[#1 Removal] = 0:0-2:0 + >---- +0| try: +1| pass +2| except* ValueError as eg: + < + [#1 Insertion delimiter] = "\n" [#2 Content] = -[#2 Removal] = [#2 Domain] = 2:0-3:8 >------------------------- 2| except* ValueError as eg: 3| pass --------< +[#2 Removal] = 2:0-4:0 + >------------------------- +2| except* ValueError as eg: +3| pass +4| else: + < + [#2 Insertion delimiter] = "\n" [#3 Content] = -[#3 Removal] = [#3 Domain] = 4:0-5:8 >----- 4| else: 5| pass --------< +[#3 Removal] = 3:8-5:8 + > +3| pass +4| else: +5| pass + --------< + [#3 Insertion delimiter] = "\n" diff --git a/data/fixtures/scopes/rust/string.singleLine.scope b/data/fixtures/scopes/rust/string.singleLine.scope index 68b4966a86..d4d6e2488e 100644 --- a/data/fixtures/scopes/rust/string.singleLine.scope +++ b/data/fixtures/scopes/rust/string.singleLine.scope @@ -4,27 +4,42 @@ r##"ccc"## --- [#1 Content] = -[#1 Removal] = [#1 Domain] = 0:0-0:5 >-----< 0| "aaa" +[#1 Removal] = 0:0-1:0 + >----- +0| "aaa" +1| r#"bbb"# + < + [#1 Insertion delimiter] = " " [#2 Content] = -[#2 Removal] = [#2 Domain] = 1:0-1:8 >--------< 1| r#"bbb"# +[#2 Removal] = 1:0-2:0 + >-------- +1| r#"bbb"# +2| r##"ccc"## + < + [#2 Insertion delimiter] = " " [#3 Content] = -[#3 Removal] = [#3 Domain] = 2:0-2:10 >----------< 2| r##"ccc"## +[#3 Removal] = 1:8-2:10 + > +1| r#"bbb"# +2| r##"ccc"## + ----------< + [#3 Insertion delimiter] = " " diff --git a/data/fixtures/scopes/textual/collectionItem.textual12.scope b/data/fixtures/scopes/textual/collectionItem.textual12.scope index 441a9eecad..8faff3390f 100644 --- a/data/fixtures/scopes/textual/collectionItem.textual12.scope +++ b/data/fixtures/scopes/textual/collectionItem.textual12.scope @@ -10,9 +10,12 @@ >-< 2| 1 -[Removal] = 2:0-2:5 - >-----< +[Removal] = 2:0-4:0 + >----- 2| 1 +3| +4| ] + < [Leading delimiter] = 2:0-2:4 >----< diff --git a/data/fixtures/scopes/textual/collectionItem.textual15.scope b/data/fixtures/scopes/textual/collectionItem.textual15.scope index 0aa55f1680..bf6bcf20f4 100644 --- a/data/fixtures/scopes/textual/collectionItem.textual15.scope +++ b/data/fixtures/scopes/textual/collectionItem.textual15.scope @@ -117,9 +117,11 @@ >-----------------< 5| colWidth: [2, 10] -[#5 Removal] = 5:0-5:29 - >-----------------------------< +[#5 Removal] = 5:0-6:0 + >----------------------------- 5| colWidth: [2, 10] +6| } + < [#5 Leading delimiter] = 5:0-5:12 >------------< diff --git a/data/fixtures/scopes/typescript.core/namedFunction.constructor.scope b/data/fixtures/scopes/typescript.core/namedFunction.constructor.scope index 35a859b925..8337f095f7 100644 --- a/data/fixtures/scopes/typescript.core/namedFunction.constructor.scope +++ b/data/fixtures/scopes/typescript.core/namedFunction.constructor.scope @@ -10,9 +10,11 @@ class MyClass { >--------------------------< 1| constructor(value: string) -[#1 Removal] = 1:0-1:28 - >----------------------------< +[#1 Removal] = 1:0-2:0 + >---------------------------- 1| constructor(value: string) +2| constructor(value: number); + < [#1 Leading delimiter] = 1:0-1:2 >--< @@ -26,9 +28,11 @@ class MyClass { >---------------------------< 2| constructor(value: number); -[#2 Removal] = 2:0-2:29 - >-----------------------------< +[#2 Removal] = 2:0-3:0 + >----------------------------- 2| constructor(value: number); +3| constructor(value: string | number) {} + < [#2 Leading delimiter] = 2:0-2:2 >--< @@ -42,9 +46,11 @@ class MyClass { >--------------------------------------< 3| constructor(value: string | number) {} -[#3 Removal] = 3:0-3:40 - >----------------------------------------< +[#3 Removal] = 3:0-4:0 + >---------------------------------------- 3| constructor(value: string | number) {} +4| } + < [#3 Leading delimiter] = 3:0-3:2 >--< diff --git a/data/fixtures/scopes/typescript.core/namedFunction.method.scope b/data/fixtures/scopes/typescript.core/namedFunction.method.scope index 746533cd46..cee0e0fe48 100644 --- a/data/fixtures/scopes/typescript.core/namedFunction.method.scope +++ b/data/fixtures/scopes/typescript.core/namedFunction.method.scope @@ -10,9 +10,11 @@ class MyClass { >------------------< 1| foo(value: string) -[#1 Removal] = 1:0-1:20 - >--------------------< +[#1 Removal] = 1:0-2:0 + >-------------------- 1| foo(value: string) +2| foo(value: number); + < [#1 Leading delimiter] = 1:0-1:2 >--< @@ -26,9 +28,11 @@ class MyClass { >-------------------< 2| foo(value: number); -[#2 Removal] = 2:0-2:21 - >---------------------< +[#2 Removal] = 2:0-3:0 + >--------------------- 2| foo(value: number); +3| foo(value: string | number) {} + < [#2 Leading delimiter] = 2:0-2:2 >--< @@ -42,9 +46,11 @@ class MyClass { >------------------------------< 3| foo(value: string | number) {} -[#3 Removal] = 3:0-3:32 - >--------------------------------< +[#3 Removal] = 3:0-4:0 + >-------------------------------- 3| foo(value: string | number) {} +4| } + < [#3 Leading delimiter] = 3:0-3:2 >--< diff --git a/data/fixtures/scopes/typescript.core/namedFunction.scope b/data/fixtures/scopes/typescript.core/namedFunction.scope index a75da32da5..70e41d982a 100644 --- a/data/fixtures/scopes/typescript.core/namedFunction.scope +++ b/data/fixtures/scopes/typescript.core/namedFunction.scope @@ -4,27 +4,42 @@ function foo(value: string | number) {} --- [#1 Content] = -[#1 Removal] = [#1 Domain] = 0:0-0:27 >---------------------------< 0| function foo(value: string) +[#1 Removal] = 0:0-1:0 + >--------------------------- +0| function foo(value: string) +1| function foo(value: number); + < + [#1 Insertion delimiter] = "\n\n" [#2 Content] = -[#2 Removal] = [#2 Domain] = 1:0-1:28 >----------------------------< 1| function foo(value: number); +[#2 Removal] = 1:0-2:0 + >---------------------------- +1| function foo(value: number); +2| function foo(value: string | number) {} + < + [#2 Insertion delimiter] = "\n\n" [#3 Content] = -[#3 Removal] = [#3 Domain] = 2:0-2:39 >---------------------------------------< 2| function foo(value: string | number) {} +[#3 Removal] = 1:28-2:39 + > +1| function foo(value: number); +2| function foo(value: string | number) {} + ---------------------------------------< + [#3 Insertion delimiter] = "\n\n" diff --git a/data/fixtures/scopes/typescript.core/statement.scope b/data/fixtures/scopes/typescript.core/statement.scope index df8feb1596..0eb91cb12d 100644 --- a/data/fixtures/scopes/typescript.core/statement.scope +++ b/data/fixtures/scopes/typescript.core/statement.scope @@ -20,9 +20,11 @@ interface Aaa { >------------< 1| bbb(): void; -[#2 Removal] = 1:0-1:16 - >----------------< +[#2 Removal] = 1:0-2:0 + >---------------- 1| bbb(): void; +2| } + < [#2 Leading delimiter] = 1:0-1:4 >----< From e14e31a19656948b1541cc34fccef72e21f69b40 Mon Sep 17 00:00:00 2001 From: Phil Cohen Date: Tue, 28 Jan 2025 20:31:07 -0800 Subject: [PATCH 05/14] Update packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts --- .../util/insertionRemovalBehaviors/getSmartRemovalTarget.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts index 9d650dca8a..46c2c077ad 100644 --- a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts +++ b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts @@ -7,6 +7,11 @@ import { LineTarget } from "../../LineTarget"; import { ParagraphTarget } from "../../ParagraphTarget"; import { TokenTarget } from "../../TokenTarget"; +/** + * For targets that don't provide a removal range, we can effectively duck-type one if its content + * range matches that of a token, line, paragraph, or document. If so, we can use the removal range + * for a target of that type. + */ export function getSmartRemovalTarget(target: Target): Target { const { editor, isReversed } = target; const { document } = editor; From 2faccb07eaa28b260a39254842e8c1b9adbbcd26 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Wed, 29 Jan 2025 05:51:48 +0100 Subject: [PATCH 06/14] Remove document upgrade --- .../getSmartRemovalTarget.ts | 20 +------------------ 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts index 46c2c077ad..91854388a6 100644 --- a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts +++ b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts @@ -1,8 +1,6 @@ -import type { Range, TextDocument, TextEditor } from "@cursorless/common"; +import type { Range, TextDocument } from "@cursorless/common"; import type { Target } from "../../../../typings/target.types"; import { union } from "../../../../util/rangeUtils"; -import { shrinkRangeToFitContent } from "../../../../util/selectionUtils"; -import { DocumentTarget } from "../../DocumentTarget"; import { LineTarget } from "../../LineTarget"; import { ParagraphTarget } from "../../ParagraphTarget"; import { TokenTarget } from "../../TokenTarget"; @@ -25,14 +23,6 @@ export function getSmartRemovalTarget(target: Target): Target { }); } - if (isDocument(editor, contentRange)) { - return new DocumentTarget({ - editor, - isReversed, - contentRange: document.range, - }); - } - if (isParagraph(document, contentRange)) { return new ParagraphTarget({ editor, @@ -67,11 +57,3 @@ function isParagraph(document: TextDocument, contentRange: Range): boolean { document.lineAt(end.line + 1).isEmptyOrWhitespace) ); } - -function isDocument(editor: TextEditor, contentRange: Range): boolean { - const documentContentRange = shrinkRangeToFitContent( - editor, - editor.document.range, - ); - return documentContentRange.isRangeEqual(contentRange); -} From bda0a04058f1b0f2b17ace18488d55d37b5df0d6 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Wed, 29 Jan 2025 05:55:08 +0100 Subject: [PATCH 07/14] Change type --- .../src/processTargets/targets/ScopeTypeTarget.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/cursorless-engine/src/processTargets/targets/ScopeTypeTarget.ts b/packages/cursorless-engine/src/processTargets/targets/ScopeTypeTarget.ts index 20479540ec..f3a3712e4b 100644 --- a/packages/cursorless-engine/src/processTargets/targets/ScopeTypeTarget.ts +++ b/packages/cursorless-engine/src/processTargets/targets/ScopeTypeTarget.ts @@ -1,5 +1,10 @@ -import type { Range, SimpleScopeTypeType } from "@cursorless/common"; +import type { + GeneralizedRange, + Range, + SimpleScopeTypeType, +} from "@cursorless/common"; import type { Target } from "../../typings/target.types"; +import { toGeneralizedRange } from "../../util/targetUtils"; import type { CommonTargetParameters } from "./BaseTarget"; import { BaseTarget } from "./BaseTarget"; import { InteriorTarget } from "./InteriorTarget"; @@ -102,12 +107,12 @@ export class ScopeTypeTarget extends BaseTarget { return getSmartRemovalTarget(this).getRemovalRange(); } - getRemovalHighlightRange(): Range { + getRemovalHighlightRange(): GeneralizedRange { if (this.removalRange_ != null) { - return this.removalRange_; + return toGeneralizedRange(this, this.removalRange_); } if (this.hasDelimiterRange_) { - return getDelimitedSequenceRemovalRange(this); + return toGeneralizedRange(this, getDelimitedSequenceRemovalRange(this)); } return getSmartRemovalTarget(this).getRemovalHighlightRange(); } From 1eca55c2b62b0755f656441035bfde7f17eedfee Mon Sep 17 00:00:00 2001 From: Phil Cohen Date: Tue, 28 Jan 2025 20:58:18 -0800 Subject: [PATCH 08/14] Update packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts --- .../util/insertionRemovalBehaviors/getSmartRemovalTarget.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts index 91854388a6..3ef0dfe2f5 100644 --- a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts +++ b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts @@ -7,7 +7,7 @@ import { TokenTarget } from "../../TokenTarget"; /** * For targets that don't provide a removal range, we can effectively duck-type one if its content - * range matches that of a token, line, paragraph, or document. If so, we can use the removal range + * range matches that of a token, series of whole lines, or paragraph. If so, we can use the removal range * for a target of that type. */ export function getSmartRemovalTarget(target: Target): Target { From 31d32edb5cf82a23be0a30bad30735fcbe5ceec6 Mon Sep 17 00:00:00 2001 From: Phil Cohen Date: Tue, 28 Jan 2025 20:58:30 -0800 Subject: [PATCH 09/14] Update packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts --- .../util/insertionRemovalBehaviors/getSmartRemovalTarget.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts index 3ef0dfe2f5..eced2b5884 100644 --- a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts +++ b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts @@ -49,6 +49,9 @@ function isLine(document: TextDocument, contentRange: Range): boolean { ); } +/** + * Returns whether the given content range is a paragraph (a series of whole lines bounded by whitespace or empty lines on each side). + */ function isParagraph(document: TextDocument, contentRange: Range): boolean { const { start, end } = contentRange; return ( From 4baa92e454d8489847664a33e43c8d60e7a5b1bd Mon Sep 17 00:00:00 2001 From: Phil Cohen Date: Tue, 28 Jan 2025 21:03:56 -0800 Subject: [PATCH 10/14] Update packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts --- .../util/insertionRemovalBehaviors/getSmartRemovalTarget.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts index eced2b5884..a74c223c83 100644 --- a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts +++ b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts @@ -38,6 +38,10 @@ export function getSmartRemovalTarget(target: Target): Target { }); } +/** + * Returns whether the given content range is a series of line(s) that do not have preceding + * or trailing content (whitespace is OK). + */ function isLine(document: TextDocument, contentRange: Range): boolean { const start = document.lineAt(contentRange.start).rangeTrimmed?.start; const end = document.lineAt(contentRange.end).rangeTrimmed?.end; From 37fe29308906987ff3e5dc3d7917155795c38776 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Wed, 29 Jan 2025 06:04:49 +0100 Subject: [PATCH 11/14] Rename --- .../util/insertionRemovalBehaviors/getSmartRemovalTarget.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts index a74c223c83..072b6048cc 100644 --- a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts +++ b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts @@ -15,7 +15,7 @@ export function getSmartRemovalTarget(target: Target): Target { const { document } = editor; const contentRange = union(target.contentRange, target.prefixRange); - if (!isLine(document, contentRange)) { + if (!isWholeLines(document, contentRange)) { return new TokenTarget({ editor, isReversed, @@ -42,7 +42,7 @@ export function getSmartRemovalTarget(target: Target): Target { * Returns whether the given content range is a series of line(s) that do not have preceding * or trailing content (whitespace is OK). */ -function isLine(document: TextDocument, contentRange: Range): boolean { +function isWholeLines(document: TextDocument, contentRange: Range): boolean { const start = document.lineAt(contentRange.start).rangeTrimmed?.start; const end = document.lineAt(contentRange.end).rangeTrimmed?.end; return ( From afd8f7285e32d163332bbc624a41e21787cdd7bf Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Wed, 29 Jan 2025 06:09:20 +0100 Subject: [PATCH 12/14] Restructure --- .../getSmartRemovalTarget.ts | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts index 072b6048cc..2c30d2b409 100644 --- a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts +++ b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts @@ -15,23 +15,23 @@ export function getSmartRemovalTarget(target: Target): Target { const { document } = editor; const contentRange = union(target.contentRange, target.prefixRange); - if (!isWholeLines(document, contentRange)) { - return new TokenTarget({ - editor, - isReversed, - contentRange: contentRange, - }); - } + if (isWholeLines(document, contentRange)) { + if (hasLeadingAndTrailingEmptyLines(document, contentRange)) { + return new ParagraphTarget({ + editor, + isReversed, + contentRange: contentRange, + }); + } - if (isParagraph(document, contentRange)) { - return new ParagraphTarget({ + return new LineTarget({ editor, isReversed, contentRange: contentRange, }); } - return new LineTarget({ + return new TokenTarget({ editor, isReversed, contentRange: contentRange, @@ -56,7 +56,10 @@ function isWholeLines(document: TextDocument, contentRange: Range): boolean { /** * Returns whether the given content range is a paragraph (a series of whole lines bounded by whitespace or empty lines on each side). */ -function isParagraph(document: TextDocument, contentRange: Range): boolean { +function hasLeadingAndTrailingEmptyLines( + document: TextDocument, + contentRange: Range, +): boolean { const { start, end } = contentRange; return ( (start.line === 0 || document.lineAt(start.line - 1).isEmptyOrWhitespace) && From 4fba17df391f888f66587c41abea30a64fe09d90 Mon Sep 17 00:00:00 2001 From: Phil Cohen Date: Tue, 28 Jan 2025 21:10:08 -0800 Subject: [PATCH 13/14] Update packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts --- .../util/insertionRemovalBehaviors/getSmartRemovalTarget.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts index 2c30d2b409..b36fbf566e 100644 --- a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts +++ b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts @@ -53,9 +53,6 @@ function isWholeLines(document: TextDocument, contentRange: Range): boolean { ); } -/** - * Returns whether the given content range is a paragraph (a series of whole lines bounded by whitespace or empty lines on each side). - */ function hasLeadingAndTrailingEmptyLines( document: TextDocument, contentRange: Range, From 11a7527804d9faa3eb5819764f72a2b7e2471513 Mon Sep 17 00:00:00 2001 From: Phil Cohen Date: Tue, 28 Jan 2025 21:10:56 -0800 Subject: [PATCH 14/14] Update packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts --- .../util/insertionRemovalBehaviors/getSmartRemovalTarget.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts index b36fbf566e..da7b91bdd3 100644 --- a/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts +++ b/packages/cursorless-engine/src/processTargets/targets/util/insertionRemovalBehaviors/getSmartRemovalTarget.ts @@ -15,6 +15,7 @@ export function getSmartRemovalTarget(target: Target): Target { const { document } = editor; const contentRange = union(target.contentRange, target.prefixRange); + // NB: These are checked in order of cheapest to most expensive. if (isWholeLines(document, contentRange)) { if (hasLeadingAndTrailingEmptyLines(document, contentRange)) { return new ParagraphTarget({