Mercurial Hosting > editor
comparison editor.luan @ 16:90abee9e07d5
add show_column
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 06 Apr 2025 18:40:15 -0600 |
parents | 93e46dadb694 |
children | 273aebbcf90b |
comparison
equal
deleted
inserted
replaced
15:93e46dadb694 | 16:90abee9e07d5 |
---|---|
21 local new_menu = require("luan:swing/Menu.luan").new or error() | 21 local new_menu = require("luan:swing/Menu.luan").new or error() |
22 local new_menu_item = require("luan:swing/Menu_item.luan").new or error() | 22 local new_menu_item = require("luan:swing/Menu_item.luan").new or error() |
23 local new_check_box_menu_item = require("luan:swing/Check_box_menu_item.luan").new or error() | 23 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() | 24 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() | 25 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 show_message_dialog = Option_pane.show_message_dialog or error() | |
26 local Logging = require "luan:logging/Logging.luan" | 28 local Logging = require "luan:logging/Logging.luan" |
27 local logger = Logging.logger "editor" | 29 local logger = Logging.logger "editor" |
28 | 30 |
29 | 31 |
30 local new_window | 32 local new_window |
160 show_whitespace.add_action_listener(function() | 162 show_whitespace.add_action_listener(function() |
161 window.text_area.show_whitespace(show_whitespace.state) | 163 window.text_area.show_whitespace(show_whitespace.state) |
162 end) | 164 end) |
163 view_menu.add(show_whitespace) | 165 view_menu.add(show_whitespace) |
164 end | 166 end |
167 do | |
168 local show_column = new_menu_item() | |
169 show_column.text = "Show Cursor Column" | |
170 show_column.add_action_listener(function() | |
171 --logger.info(window.cursor_column()) | |
172 show_message_dialog( window.frame, "Cursor Column: "..window.cursor_column() ) | |
173 end) | |
174 view_menu.add(show_column) | |
175 end | |
165 menu_bar.add(view_menu) | 176 menu_bar.add(view_menu) |
166 end | 177 end |
167 return menu_bar | 178 return menu_bar |
168 end | 179 end |
169 | 180 |
172 | 183 |
173 function new_window(file) | 184 function new_window(file) |
174 local window = {} | 185 local window = {} |
175 window.has_file = file~=nil and file.is_file() | 186 window.has_file = file~=nil and file.is_file() |
176 local frame = new_frame() | 187 local frame = new_frame() |
188 window.frame = frame | |
177 local title = file and file.canonical().to_string() or "new" | 189 local title = file and file.canonical().to_string() or "new" |
178 frame.add_close_listener(function() | 190 frame.add_close_listener(function() |
179 n_windows = n_windows - 1 | 191 n_windows = n_windows - 1 |
180 if n_windows == 0 then | 192 if n_windows == 0 then |
181 Luan.exit() | 193 Luan.exit() |
293 local end_selection = r.end_selection - (len1 - len2) | 305 local end_selection = r.end_selection - (len1 - len2) |
294 text = sub_string(text,2) | 306 text = sub_string(text,2) |
295 text_area.replace(r.start_pos,r.length,text) | 307 text_area.replace(r.start_pos,r.length,text) |
296 text_area.set_selection(start_seletion,end_selection) | 308 text_area.set_selection(start_seletion,end_selection) |
297 end | 309 end |
310 function window.cursor_column() | |
311 local cursor_pos = text_area.get_selection() | |
312 local line = text_area.get_line_from_position(cursor_pos) | |
313 local start_line_pos = text_area.get_line_start_position(line) | |
314 return cursor_pos - start_line_pos + 1 | |
315 end | |
298 local menu_bar = make_menu_bar(window) | 316 local menu_bar = make_menu_bar(window) |
299 frame.set_menu_bar(menu_bar) | 317 frame.set_menu_bar(menu_bar) |
300 frame.pack() | 318 frame.pack() |
301 frame.visible = true | 319 frame.visible = true |
302 text_area.request_focus_in_window() | 320 text_area.request_focus_in_window() |