Format with stylua

This commit is contained in:
L3MON4D3 2023-05-25 13:44:06 +00:00 committed by github-actions[bot]
parent 8ed8300b50
commit 51c1741e2c
3 changed files with 203 additions and 106 deletions

View file

@ -489,7 +489,7 @@ end
-- set the rgrav of snippet adjacent to (sharing an endpoint with) the node we
-- want to focus, regardless of its position in the tree, will lead to extmarks
-- covering the wrong regions.
--
--
-- More complications: focusing a node does not always mean setting the rgravs
-- such that text will end up inside the node!
-- For example, in the case of a terminating i(0) (like s("trig", {i(1,
@ -520,7 +520,7 @@ local function focus_node(self, lrgrav, rrgrav)
-- the tree-representation of the snippet.
-- This is dubbed "direction" because it is the direction we will search in
-- to find nodes on one endpoint of self.
for _, direction in ipairs({-1,1}) do
for _, direction in ipairs({ -1, 1 }) do
local self_direction_endpoint = self.mark:get_endpoint(direction)
local direction_rgrav = util.ternary(direction == -1, lrgrav, rrgrav)
@ -530,7 +530,12 @@ local function focus_node(self, lrgrav, rrgrav)
local node = nodes_path[i]
local node_direction_endpoint = node.mark:get_endpoint(direction)
if not util.pos_equal(node_direction_endpoint, self_direction_endpoint) then
if
not util.pos_equal(
node_direction_endpoint,
self_direction_endpoint
)
then
-- stop adjusting rgravs once self no longer is on the boundary of
-- its parents, or if the rgrav is already set correctly.
break
@ -541,13 +546,28 @@ local function focus_node(self, lrgrav, rrgrav)
-- can't use node.parent, since that might skip nodes (in the case of
-- dynamicNode, for example, the generated snippets parent is not the
-- dynamicNode, but its parent).
-- also: don't need to check for nil, because the
local node_above = nodes_path[i-1]
if node_above and (node_above.type == types.snippetNode or node_above.type == types.snippet) then
node_above:set_sibling_rgravs(self_direction_endpoint, abs_pos[i], direction, direction_rgrav)
-- also: don't need to check for nil, because the
local node_above = nodes_path[i - 1]
if
node_above
and (
node_above.type == types.snippetNode
or node_above.type == types.snippet
)
then
node_above:set_sibling_rgravs(
self_direction_endpoint,
abs_pos[i],
direction,
direction_rgrav
)
end
end
self:subtree_set_pos_rgrav(self_direction_endpoint, -direction, direction_rgrav)
self:subtree_set_pos_rgrav(
self_direction_endpoint,
-direction,
direction_rgrav
)
end
end
@ -585,5 +605,5 @@ end
return {
Node = Node,
focus_node = focus_node
focus_node = focus_node,
}

View file

@ -1139,7 +1139,13 @@ end
-- assumption: direction-endpoint of node at child_from_indx is on child_endpoint.
-- (caller responsible)
local function adjust_children_rgravs(self, child_endpoint, child_from_indx, direction, rgrav)
local function adjust_children_rgravs(
self,
child_endpoint,
child_from_indx,
direction,
rgrav
)
local i = child_from_indx
local node = self.nodes[i]
while node do
@ -1157,7 +1163,7 @@ local function adjust_children_rgravs(self, child_endpoint, child_from_indx, dir
break
end
i = i+direction
i = i + direction
node = self.nodes[i]
end
end
@ -1165,8 +1171,19 @@ end
-- adjust rgrav of nodes left (direction=-1) or right (direction=1) of node at
-- child_indx.
-- (direction is the direction into which is searched, from child_indx outward)
function Snippet:set_sibling_rgravs(child_endpoint, child_indx, direction, rgrav)
adjust_children_rgravs(self, child_endpoint, child_indx+direction, direction, rgrav)
function Snippet:set_sibling_rgravs(
child_endpoint,
child_indx,
direction,
rgrav
)
adjust_children_rgravs(
self,
child_endpoint,
child_indx + direction,
direction,
rgrav
)
end
-- called only if the "-direction"-endpoint has to be changed, but the

View file

@ -882,152 +882,201 @@ describe("snippets_basic", function()
]])
feed("aa")
screen:expect{grid=[[
screen:expect({
grid = [[
aa^ |
{0:~ }|
{2:-- INSERT --} |]]}
{2:-- INSERT --} |]],
})
exec_lua("ls.jump(1)")
-- will insert here later.
exec_lua("ls.jump(1)")
feed("cc")
screen:expect{grid=[[
screen:expect({
grid = [[
aacc^ |
{0:~ }|
{2:-- INSERT --} |]]}
{2:-- INSERT --} |]],
})
exec_lua("ls.jump(1)")
feed("dd")
screen:expect{grid=[[
screen:expect({
grid = [[
aadd^cc |
{0:~ }|
{2:-- INSERT --} |]]}
{2:-- INSERT --} |]],
})
exec_lua("ls.jump(1)")
feed("ee")
screen:expect{grid=[[
screen:expect({
grid = [[
aaddccee^ |
{0:~ }|
{2:-- INSERT --} |]]}
{2:-- INSERT --} |]],
})
exec_lua("ls.jump(-1)")
screen:expect{grid=[[
screen:expect({
grid = [[
aa^d{3:d}ccee |
{0:~ }|
{2:-- SELECT --} |]]}
{2:-- SELECT --} |]],
})
exec_lua("ls.jump(-1)")
screen:expect{grid=[[
screen:expect({
grid = [[
aadd^c{3:c}ee |
{0:~ }|
{2:-- SELECT --} |]]}
{2:-- SELECT --} |]],
})
exec_lua("ls.jump(-1)")
feed("bb")
screen:expect{grid=[[
screen:expect({
grid = [[
aabb^ddccee |
{0:~ }|
{2:-- INSERT --} |]]}
{2:-- INSERT --} |]],
})
exec_lua("ls.jump(-1)")
screen:expect{grid=[[
screen:expect({
grid = [[
^a{3:a}bbddccee |
{0:~ }|
{2:-- SELECT --} |]]}
{2:-- SELECT --} |]],
})
exec_lua("ls.jump(1)")
screen:expect{grid=[[
screen:expect({
grid = [[
aa^b{3:b}ddccee |
{0:~ }|
{2:-- SELECT --} |]]}
{2:-- SELECT --} |]],
})
end)
it("text is inserted into the selected node, when dynamicNode is present", function()
exec_lua([[
it(
"text is inserted into the selected node, when dynamicNode is present",
function()
exec_lua([[
ls.snip_expand(s("", {
i(4), i(1), d(2, function()
return sn(nil, {i(2), i(1)})
end, {3}), i(3, "text??")
}))
]])
screen:expect{grid=[[
screen:expect({
grid = [[
^text?? |
{0:~ }|
{2:-- INSERT --} |]]}
{2:-- INSERT --} |]],
})
exec_lua("ls.jump(1) ls.jump(1) ls.jump(1)")
feed("refresh dNode ")
screen:expect{grid=[[
exec_lua("ls.jump(1) ls.jump(1) ls.jump(1)")
feed("refresh dNode ")
screen:expect({
grid = [[
refresh dNode ^ |
{0:~ }|
{2:-- INSERT --} |]]}
exec_lua("ls.jump(1)")
screen:expect{grid=[[
{2:-- INSERT --} |]],
})
exec_lua("ls.jump(1)")
screen:expect({
grid = [[
^refresh dNode |
{0:~ }|
{2:-- INSERT --} |]]}
feed("shifts dNode?")
screen:expect{grid=[[
{2:-- INSERT --} |]],
})
feed("shifts dNode?")
screen:expect({
grid = [[
shifts dNode?^refresh dNode |
{0:~ }|
{2:-- INSERT --} |]]}
-- doing all jump in the same exec_lua fails :/
-- Maybe some weird timing-issue with feed..
exec_lua("ls.jump(-1)")
exec_lua("ls.jump(-1)")
exec_lua("ls.jump(-1)")
exec_lua("ls.jump(-1)")
feed(" also shifts dNode ")
screen:expect{grid=[[
{2:-- INSERT --} |]],
})
-- doing all jump in the same exec_lua fails :/
-- Maybe some weird timing-issue with feed..
exec_lua("ls.jump(-1)")
exec_lua("ls.jump(-1)")
exec_lua("ls.jump(-1)")
exec_lua("ls.jump(-1)")
feed(" also shifts dNode ")
screen:expect({
grid = [[
shifts dNode?also shifts dNode ^refresh dNode |
{0:~ }|
{2:-- INSERT --} |]]}
exec_lua("ls.jump(1)")
feed(" dNode1 ")
screen:expect{grid=[[
{2:-- INSERT --} |]],
})
exec_lua("ls.jump(1)")
feed(" dNode1 ")
screen:expect({
grid = [[
shifts dNode?also shifts dNode dNode1 ^refresh dNod|
e |
{2:-- INSERT --} |]]}
{2:-- INSERT --} |]],
})
exec_lua("ls.jump(1)")
feed(" dNode2 ")
screen:expect{grid=[[
exec_lua("ls.jump(1)")
feed(" dNode2 ")
screen:expect({
grid = [[
shifts dNode?also shifts dNode dNode2 ^dNode1 refre|
sh dNode |
{2:-- INSERT --} |]]}
{2:-- INSERT --} |]],
})
exec_lua("ls.jump(-1)")
exec_lua("ls.jump(-1)")
screen:expect{grid=[[
exec_lua("ls.jump(-1)")
exec_lua("ls.jump(-1)")
screen:expect({
grid = [[
shifts dNode?^a{3:lso shifts dNode }dNode2 dNode1 refre|
sh dNode |
{2:-- SELECT --} |]]}
{2:-- SELECT --} |]],
})
exec_lua("ls.jump(1)")
screen:expect{grid=[[
exec_lua("ls.jump(1)")
screen:expect({
grid = [[
shifts dNode?also shifts dNode dNode2 ^d{3:Node1 }refre|
sh dNode |
{2:-- SELECT --} |]]}
exec_lua("ls.jump(1)")
screen:expect{grid=[[
{2:-- SELECT --} |]],
})
exec_lua("ls.jump(1)")
screen:expect({
grid = [[
shifts dNode?also shifts dNode ^d{3:Node2 }dNode1 refre|
sh dNode |
{2:-- SELECT --} |]]}
exec_lua("ls.jump(1)")
screen:expect{grid=[[
{2:-- SELECT --} |]],
})
exec_lua("ls.jump(1)")
screen:expect({
grid = [[
shifts dNode?also shifts dNode dNode2 dNode1 ^r{3:efre}|
{3:sh dNode } |
{2:-- SELECT --} |]]}
exec_lua("ls.jump(1)")
screen:expect{grid=[[
{2:-- SELECT --} |]],
})
exec_lua("ls.jump(1)")
screen:expect({
grid = [[
^s{3:hifts dNode?}also shifts dNode dNode2 dNode1 refre|
sh dNode |
{2:-- SELECT --} |]]}
exec_lua("ls.jump(1)")
screen:expect{grid=[[
{2:-- SELECT --} |]],
})
exec_lua("ls.jump(1)")
screen:expect({
grid = [[
shifts dNode?also shifts dNode dNode2 dNode1 refre|
sh dNode ^ |
{2:-- INSERT --} |]]}
end)
it("text is inserted into the selected node, when choiceNode is present", function()
exec_lua([[
{2:-- INSERT --} |]],
})
end
)
it(
"text is inserted into the selected node, when choiceNode is present",
function()
exec_lua([[
ls.snip_expand(s("", {
i(1),
c(2, {
@ -1037,40 +1086,51 @@ describe("snippets_basic", function()
i(3, "text??")
}))
]])
screen:expect{grid=[[
screen:expect({
grid = [[
^asdftext?? |
{0:~ }|
{2:-- INSERT --} |]]}
{2:-- INSERT --} |]],
})
-- jump to i3
exec_lua("ls.jump(1) ls.jump(1)")
feed("1111")
screen:expect{grid=[[
-- jump to i3
exec_lua("ls.jump(1) ls.jump(1)")
feed("1111")
screen:expect({
grid = [[
asdf1111^ |
{0:~ }|
{2:-- INSERT --} |]]}
{2:-- INSERT --} |]],
})
-- change choice, jump back
exec_lua("ls.jump(-1) ls.change_choice(1) ls.jump(1)")
feed("2222")
screen:expect{grid=[[
-- change choice, jump back
exec_lua("ls.jump(-1) ls.change_choice(1) ls.jump(1)")
feed("2222")
screen:expect({
grid = [[
2222^ |
{0:~ }|
{2:-- INSERT --} |]]}
{2:-- INSERT --} |]],
})
-- back to i1
exec_lua("ls.jump(-1) ls.jump(-1)")
feed("3333")
screen:expect{grid=[[
-- back to i1
exec_lua("ls.jump(-1) ls.jump(-1)")
feed("3333")
screen:expect({
grid = [[
3333^2222 |
{0:~ }|
{2:-- INSERT --} |]]}
{2:-- INSERT --} |]],
})
exec_lua("ls.jump(1)")
feed("4444")
screen:expect{grid=[[
exec_lua("ls.jump(1)")
feed("4444")
screen:expect({
grid = [[
33334444^2222 |
{0:~ }|
{2:-- INSERT --} |]]}
end)
{2:-- INSERT --} |]],
})
end
)
end)