Skip to content

Commit c8302bb

Browse files
committed
feat: handle special value of jsx elements (always goes to end of element tag)
1 parent fdbfb93 commit c8302bb

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

typescript/src/specialCommands/handle.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { compact } from '@zardoy/utils'
22
import postfixesAtPosition from '../completions/postfixesAtPosition'
33
import { NodeAtPositionResponse, RequestOptionsTypes, RequestResponseTypes, TriggerCharacterCommand, triggerCharacterCommands } from '../ipcTypes'
4-
import { findChildContainingPosition, getNodePath } from '../utils'
4+
import { findChildContainingExactPosition, findChildContainingPosition, getNodePath } from '../utils'
55
import getEmmetCompletions from './emmet'
66
import objectIntoArrayConverters from './objectIntoArrayConverters'
77

@@ -121,7 +121,7 @@ export default (
121121
}
122122
}
123123
if (specialCommand === 'getRangeOfSpecialValue') {
124-
let node = findChildContainingPosition(ts, sourceFile, position)
124+
let node = findChildContainingExactPosition(sourceFile, position)
125125
if (!node) return
126126
let targetNode: undefined | ts.Node | [number, number]
127127
if (ts.isIdentifier(node) && node.parent) {
@@ -130,6 +130,9 @@ export default (
130130
targetNode = node.initializer
131131
} else if ('body' in node) {
132132
targetNode = node.body as ts.Node
133+
} else if (ts.isJsxOpeningElement(node) || ts.isJsxOpeningFragment(node) || ts.isJsxSelfClosingElement(node)) {
134+
const pos = node.end
135+
targetNode = [pos, pos]
133136
}
134137
}
135138

@@ -156,6 +159,10 @@ export default (
156159
targetNode = n.thenStatement
157160
return true
158161
}
162+
if (ts.isIfStatement(n) && position < n.thenStatement.pos) {
163+
targetNode = n.thenStatement
164+
return true
165+
}
159166
return false
160167
})
161168
}

0 commit comments

Comments
 (0)