mirror of
https://github.com/leporello-js/leporello-js
synced 2026-01-13 21:14:28 -08:00
Fix selection selects unevaluatable node
This commit is contained in:
11
src/cmd.js
11
src/cmd.js
@@ -374,16 +374,11 @@ const get_next_selection_state = (selection_state, frame, is_expand, index) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// TODO when collapsing, also check that node is evaluatable
|
|
||||||
// collapse
|
// collapse
|
||||||
if(selection_state.node.children != null){
|
if(selection_state.node.children != null){
|
||||||
next_node =
|
const leaf = find_leaf(selection_state.node, index)
|
||||||
selection_state.node.children.find(n =>
|
next_node = ancestry_inc(leaf, selection_state.node)
|
||||||
n.index <= index && n.index + n.length > index
|
.findLast(n => !n.not_evaluatable && n != selection_state.node)
|
||||||
)
|
|
||||||
??
|
|
||||||
// cursor not inside child but in whitespace
|
|
||||||
selection_state.node
|
|
||||||
} else {
|
} else {
|
||||||
// no children, cannot collapse
|
// no children, cannot collapse
|
||||||
next_node = selection_state.node
|
next_node = selection_state.node
|
||||||
|
|||||||
11
test/test.js
11
test/test.js
@@ -2131,6 +2131,17 @@ const y = x()`
|
|||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
test('eval_selection bug', () => {
|
||||||
|
const code = `{foo: 1}`
|
||||||
|
const i = test_initial_state(code)
|
||||||
|
const index = code.indexOf('1')
|
||||||
|
const moved = COMMANDS.move_cursor(i, index)
|
||||||
|
const selection = COMMANDS.eval_selection(moved, index, true).state
|
||||||
|
const selection2 = COMMANDS.eval_selection(selection, index, true).state
|
||||||
|
const selection3 = COMMANDS.eval_selection(selection2, index, false).state
|
||||||
|
assert_equal(selection3.selection_state.node.value, '1')
|
||||||
|
}),
|
||||||
|
|
||||||
test('find_call', () => {
|
test('find_call', () => {
|
||||||
const code = `
|
const code = `
|
||||||
const y = () => y2()
|
const y = () => y2()
|
||||||
|
|||||||
Reference in New Issue
Block a user