@@ -64,8 +64,8 @@ suite("Delimiters Test Suite", () => {
6464
6565 test ( "Should handle quote selection scenarios from issue" , ( ) => {
6666 // This test documents the expected behavior for the issue scenarios
67- // Scenario 1: At position 1 , should select content between outer quotes (1:35)
68- // Scenario 2: At position 5 , should select "prop1" (5:10 )
67+ // Scenario 1: At position 3 , should select content between outer quotes (1:35)
68+ // Scenario 2: At position 6 , should select "prop1" (5:9 )
6969
7070 const testString = '"[{\\"prop1\\":0,\\"prop2\\":\\"value2\\"]"' ;
7171
@@ -78,10 +78,19 @@ suite("Delimiters Test Suite", () => {
7878 assert . strictEqual ( isEscapedQuote ( testString , 4 ) , true , "Quote at position 4 is escaped" ) ;
7979 assert . strictEqual ( isEscapedQuote ( testString , 11 ) , true , "Quote at position 11 is escaped" ) ;
8080
81- // Verify the fix handles both scenarios:
82- // 1. Unescaped quotes (0,36) should pair together for outer selection
83- // 2. Escaped quotes (4,11) should pair together for inner selection
84- // 3. Selection should exclude escape characters from the content
81+ // Test the fix: cursor at position 6 should find escaped quote pair (4, 11)
82+ // and adjust selection to exclude escape characters
83+ // Expected selection: position 5 to 9 (content: "prop1")
84+
85+ // Simulate text split at cursor position 6
86+ const textBeforeCursor = testString . substring ( 0 , 6 ) ; // "[{\"p
87+ const textAfterCursor = testString . substring ( 6 ) ; // rop1\":0,\"prop2\":\"value2\" }]"
88+
89+ // Opening quote should be at position 4 (escaped)
90+ assert . strictEqual ( isEscapedQuote ( textBeforeCursor , 4 ) , true , "Opening quote at position 4 is escaped" ) ;
91+
92+ // Closing quote should be at position 5 in textAfterCursor (position 11 in full string, escaped)
93+ assert . strictEqual ( isEscapedQuote ( textAfterCursor , 5 ) , true , "Closing quote at relative position 5 is escaped" ) ;
8594
8695 assert . ok ( true , "Enhanced escape detection and pairing implemented for delimiter matching" ) ;
8796 } ) ;
@@ -108,4 +117,49 @@ suite("Delimiters Test Suite", () => {
108117
109118 assert . ok ( true , "Escaped quote pairing and selection positioning implemented" ) ;
110119 } ) ;
120+
121+ test ( "Should fix specific issue: cursor at position 6 selects 'prop1'" , ( ) => {
122+ // Test the exact issue reported by the user
123+ // String: "[{\"prop1\":0,\"prop2\":\"value2\"}]"
124+ // Cursor at position 6 should select "prop1" from position 5 to position 9
125+
126+ const testString = '"[{\\"prop1\\":0,\\"prop2\\":\\"value2\\"]"' ;
127+
128+ // Simulate cursor at position 6 (on 'r' in "prop1")
129+ const cursorPosition = 6 ;
130+ const textBefore = testString . substring ( 0 , cursorPosition ) ; // "[{\"p
131+ const textAfter = testString . substring ( cursorPosition ) ; // rop1\":0,\"prop2\":\"value2\" }]"
132+
133+ // The opening quote should be the escaped quote at position 4
134+ let openingPosition = - 1 ;
135+ for ( let i = textBefore . length - 1 ; i >= 0 ; i -- ) {
136+ if ( textBefore [ i ] === '"' ) {
137+ openingPosition = i ;
138+ break ;
139+ }
140+ }
141+ assert . strictEqual ( openingPosition , 4 , "Should find opening quote at position 4" ) ;
142+ assert . strictEqual ( isEscapedQuote ( textBefore , 4 ) , true , "Opening quote should be escaped" ) ;
143+
144+ // The closing quote should be the escaped quote at relative position 5 in textAfter
145+ let closingPosition = - 1 ;
146+ for ( let i = 0 ; i < textAfter . length ; i ++ ) {
147+ if ( textAfter [ i ] === '"' ) {
148+ closingPosition = i ;
149+ break ;
150+ }
151+ }
152+ assert . strictEqual ( closingPosition , 5 , "Should find closing quote at relative position 5" ) ;
153+ assert . strictEqual ( isEscapedQuote ( textAfter , 5 ) , true , "Closing quote should be escaped" ) ;
154+
155+ // With the fix, selection should be:
156+ // Start: after the opening escaped quote (position 5)
157+ // End: before the closing escaped quote's backslash (position 9)
158+ const expectedSelectionStart = 5 ;
159+ const expectedSelectionEnd = 9 ;
160+ const expectedContent = "prop1" ;
161+ const actualContent = testString . substring ( expectedSelectionStart , expectedSelectionEnd ) ;
162+
163+ assert . strictEqual ( actualContent , expectedContent , `Should select "${ expectedContent } " but got "${ actualContent } "` ) ;
164+ } ) ;
111165} ) ;
0 commit comments