Mercurial Hosting > editor
changeset 17:273aebbcf90b
add goto
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 06 Apr 2025 19:21:25 -0600 |
parents | 90abee9e07d5 |
children | fd6d0162e924 |
files | editor.luan |
diffstat | 1 files changed, 20 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/editor.luan Sun Apr 06 18:40:15 2025 -0600 +++ b/editor.luan Sun Apr 06 19:21:25 2025 -0600 @@ -6,6 +6,7 @@ local sub_string = String.sub or error() local replace = String.replace or error() local starts_with = String.starts_with or error() +local to_number = String.to_number or error() local Io = require "luan:Io.luan" local print = Io.print or error() local new_file = Io.schemes.file or error() @@ -25,6 +26,7 @@ local create_empty_border = require("luan:swing/Border.luan").create_empty_border or error() local Option_pane = require "luan:swing/Option_pane.luan" local show_message_dialog = Option_pane.show_message_dialog or error() +local show_input_dialog = Option_pane.show_input_dialog or error() local Logging = require "luan:logging/Logging.luan" local logger = Logging.logger "editor" @@ -168,11 +170,24 @@ local show_column = new_menu_item() show_column.text = "Show Cursor Column" show_column.add_action_listener(function() - --logger.info(window.cursor_column()) show_message_dialog( window.frame, "Cursor Column: "..window.cursor_column() ) end) view_menu.add(show_column) end + do + local goto = new_menu_item() + goto.text = "Goto Line" + goto.accelerator = "meta G" + goto.add_action_listener(function() + local input = show_input_dialog( window.frame, "Cursor Column: "..window.cursor_column() ) + --logger.info("input "..input) + local line = input and to_number(input) + if line ~= nil then + window.goto(line) + end + end) + view_menu.add(goto) + end menu_bar.add(view_menu) end return menu_bar @@ -313,6 +328,10 @@ local start_line_pos = text_area.get_line_start_position(line) return cursor_pos - start_line_pos + 1 end + function window.goto(line) + local pos = text_area.get_line_start_position(line) + text_area.set_selection(pos) + end local menu_bar = make_menu_bar(window) frame.set_menu_bar(menu_bar) frame.pack()