Mercurial Hosting > editor
comparison editor.luan @ 17:273aebbcf90b
add goto
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Sun, 06 Apr 2025 19:21:25 -0600 |
| parents | 90abee9e07d5 |
| children | fd6d0162e924 |
comparison
equal
deleted
inserted
replaced
| 16:90abee9e07d5 | 17:273aebbcf90b |
|---|---|
| 4 local stringify = Luan.stringify or error() | 4 local stringify = Luan.stringify or error() |
| 5 local String = require "luan:String.luan" | 5 local String = require "luan:String.luan" |
| 6 local sub_string = String.sub or error() | 6 local sub_string = String.sub or error() |
| 7 local replace = String.replace or error() | 7 local replace = String.replace or error() |
| 8 local starts_with = String.starts_with or error() | 8 local starts_with = String.starts_with or error() |
| 9 local to_number = String.to_number or error() | |
| 9 local Io = require "luan:Io.luan" | 10 local Io = require "luan:Io.luan" |
| 10 local print = Io.print or error() | 11 local print = Io.print or error() |
| 11 local new_file = Io.schemes.file or error() | 12 local new_file = Io.schemes.file or error() |
| 12 local Math = require "luan:Math.luan" | 13 local Math = require "luan:Math.luan" |
| 13 local min = Math.min or error() | 14 local min = Math.min or error() |
| 23 local new_check_box_menu_item = require("luan:swing/Check_box_menu_item.luan").new or error() | 24 local new_check_box_menu_item = require("luan:swing/Check_box_menu_item.luan").new or error() |
| 24 local int_to_color = require("luan:swing/Color.luan").int_to_color or error() | 25 local int_to_color = require("luan:swing/Color.luan").int_to_color or error() |
| 25 local create_empty_border = require("luan:swing/Border.luan").create_empty_border or error() | 26 local create_empty_border = require("luan:swing/Border.luan").create_empty_border or error() |
| 26 local Option_pane = require "luan:swing/Option_pane.luan" | 27 local Option_pane = require "luan:swing/Option_pane.luan" |
| 27 local show_message_dialog = Option_pane.show_message_dialog or error() | 28 local show_message_dialog = Option_pane.show_message_dialog or error() |
| 29 local show_input_dialog = Option_pane.show_input_dialog or error() | |
| 28 local Logging = require "luan:logging/Logging.luan" | 30 local Logging = require "luan:logging/Logging.luan" |
| 29 local logger = Logging.logger "editor" | 31 local logger = Logging.logger "editor" |
| 30 | 32 |
| 31 | 33 |
| 32 local new_window | 34 local new_window |
| 166 end | 168 end |
| 167 do | 169 do |
| 168 local show_column = new_menu_item() | 170 local show_column = new_menu_item() |
| 169 show_column.text = "Show Cursor Column" | 171 show_column.text = "Show Cursor Column" |
| 170 show_column.add_action_listener(function() | 172 show_column.add_action_listener(function() |
| 171 --logger.info(window.cursor_column()) | |
| 172 show_message_dialog( window.frame, "Cursor Column: "..window.cursor_column() ) | 173 show_message_dialog( window.frame, "Cursor Column: "..window.cursor_column() ) |
| 173 end) | 174 end) |
| 174 view_menu.add(show_column) | 175 view_menu.add(show_column) |
| 176 end | |
| 177 do | |
| 178 local goto = new_menu_item() | |
| 179 goto.text = "Goto Line" | |
| 180 goto.accelerator = "meta G" | |
| 181 goto.add_action_listener(function() | |
| 182 local input = show_input_dialog( window.frame, "Cursor Column: "..window.cursor_column() ) | |
| 183 --logger.info("input "..input) | |
| 184 local line = input and to_number(input) | |
| 185 if line ~= nil then | |
| 186 window.goto(line) | |
| 187 end | |
| 188 end) | |
| 189 view_menu.add(goto) | |
| 175 end | 190 end |
| 176 menu_bar.add(view_menu) | 191 menu_bar.add(view_menu) |
| 177 end | 192 end |
| 178 return menu_bar | 193 return menu_bar |
| 179 end | 194 end |
| 311 local cursor_pos = text_area.get_selection() | 326 local cursor_pos = text_area.get_selection() |
| 312 local line = text_area.get_line_from_position(cursor_pos) | 327 local line = text_area.get_line_from_position(cursor_pos) |
| 313 local start_line_pos = text_area.get_line_start_position(line) | 328 local start_line_pos = text_area.get_line_start_position(line) |
| 314 return cursor_pos - start_line_pos + 1 | 329 return cursor_pos - start_line_pos + 1 |
| 315 end | 330 end |
| 331 function window.goto(line) | |
| 332 local pos = text_area.get_line_start_position(line) | |
| 333 text_area.set_selection(pos) | |
| 334 end | |
| 316 local menu_bar = make_menu_bar(window) | 335 local menu_bar = make_menu_bar(window) |
| 317 frame.set_menu_bar(menu_bar) | 336 frame.set_menu_bar(menu_bar) |
| 318 frame.pack() | 337 frame.pack() |
| 319 frame.visible = true | 338 frame.visible = true |
| 320 text_area.request_focus_in_window() | 339 text_area.request_focus_in_window() |
