From 876af1d3f9368dd83b5a1e947099e9316780642d Mon Sep 17 00:00:00 2001 From: Johannes Wolf Date: Thu, 18 Apr 2024 21:49:25 +0200 Subject: [PATCH] edit: Force string --- config/bindings.lua | 1 + dialog/input.lua | 8 +++++++- rpn/controller.lua | 12 +++++++++++- views/edit.lua | 1 + 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/config/bindings.lua b/config/bindings.lua index c35dd6c..70bed94 100644 --- a/config/bindings.lua +++ b/config/bindings.lua @@ -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' } diff --git a/dialog/input.lua b/dialog/input.lua index 0dbf2fe..6199b5c 100644 --- a/dialog/input.lua +++ b/dialog/input.lua @@ -176,7 +176,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 diff --git a/rpn/controller.lua b/rpn/controller.lua index cf184d4..2cd0897 100644 --- a/rpn/controller.lua +++ b/rpn/controller.lua @@ -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 diff --git a/views/edit.lua b/views/edit.lua index 4979120..2063185 100644 --- a/views/edit.lua +++ b/views/edit.lua @@ -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]