Skip to content

Commit

Permalink
edit: Force string
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-wolf committed Apr 18, 2024
1 parent e20ff48 commit 38d9982
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/bindings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ return {
t['d'] = { function(_) ctrl:diff_interactive() end, 'Derivative*' }
t['i'] = { function(_) ctrl:integrate_interactive() end, 'Integrate*' }
t['f'] = { function(_) ctrl:call_n_interactive() end, 'Call*' }
t['q'] = { function(_) ctrl:seq_interactive() end, 'Seq*' }
t['right'] = { function(_) ctrl:roll_down() end, 'Roll down' }
t['left'] = { function(_) ctrl:roll_up() end, 'Roll up' }

Expand Down
8 changes: 7 additions & 1 deletion dialog/input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,13 @@ function t.display_n(n, options, on_init)
end

dlg.window:layout_children()
if options.text then dlg.edit[1]:insert_text(options.text, true) end
if type(options.text) == 'table' then
for i, v in ipairs(options.text) do
dlg.edit[i]:insert_text(v or "", true)
end
elseif options.text then
dlg.edit[1]:insert_text(options.text, true)
end
if options.cursor then dlg.edit[1]:set_cursor(options.cursor) end

if on_init then
Expand Down
12 changes: 11 additions & 1 deletion rpn/controller.lua
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,21 @@ function meta:integrate_interactive()
end
end

cmd('Seq*', 'seq_interactive')
function meta:seq_interactive()
local top = self.stack:top() and self.stack:top().infix or ""
local dlg = ask_n(4, { title = "Seq ...", text = {top, 'x', '1', '10'} })
dlg.on_done = function(args)
local e, v, i, j = table.unpack(args)
self.stack:push_infix(string.format('seq(%s,%s,%s,%s)', e, v, i, j))
end
end

cmd('Call n', 'call_n_interactive')
function meta:call_n_interactive()
if not self.stack:top() then return end

local dlg = ask_n(2, { title = string.format("Call ...", self.stack:top().infix or '?'), text = '' })
local dlg = ask_n(2, { title = "Call ...", text = {'f1(x)', '1'} })
dlg.on_done = function(text)
local fn, n = table.unpack(text)
if fn:len() == 0 then return end
Expand Down
1 change: 1 addition & 0 deletions views/edit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ end
---@param text string Text to insert at the current cursor position
---@param sel boolean Select inserted text
function ui.edit:insert_text(text, sel)
text = tostring(text)
local left, mid, right = self:split_text()

local closing_paren = ui.edit.paren_pairs[text]
Expand Down

0 comments on commit 38d9982

Please sign in to comment.