Mercurial Hosting > editor
changeset 16:90abee9e07d5
add show_column
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 06 Apr 2025 18:40:15 -0600 |
parents | 93e46dadb694 |
children | 273aebbcf90b |
files | editor.luan |
diffstat | 1 files changed, 18 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/editor.luan Sun Apr 06 16:34:58 2025 -0600 +++ b/editor.luan Sun Apr 06 18:40:15 2025 -0600 @@ -23,6 +23,8 @@ local new_check_box_menu_item = require("luan:swing/Check_box_menu_item.luan").new or error() local int_to_color = require("luan:swing/Color.luan").int_to_color or error() 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 Logging = require "luan:logging/Logging.luan" local logger = Logging.logger "editor" @@ -162,6 +164,15 @@ end) view_menu.add(show_whitespace) end + do + 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 menu_bar.add(view_menu) end return menu_bar @@ -174,6 +185,7 @@ local window = {} window.has_file = file~=nil and file.is_file() local frame = new_frame() + window.frame = frame local title = file and file.canonical().to_string() or "new" frame.add_close_listener(function() n_windows = n_windows - 1 @@ -295,6 +307,12 @@ text_area.replace(r.start_pos,r.length,text) text_area.set_selection(start_seletion,end_selection) end + function window.cursor_column() + local cursor_pos = text_area.get_selection() + local line = text_area.get_line_from_position(cursor_pos) + local start_line_pos = text_area.get_line_start_position(line) + return cursor_pos - start_line_pos + 1 + end local menu_bar = make_menu_bar(window) frame.set_menu_bar(menu_bar) frame.pack()