changeset 38:8c90e0077cfe default tip

add duplicate window
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 15 May 2025 11:03:48 -0600
parents b7ff52d45b9a
children
files src/luan_editor/menu.luan src/luan_editor/window.luan
diffstat 2 files changed, 18 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan_editor/menu.luan	Mon Apr 21 13:07:29 2025 -0600
+++ b/src/luan_editor/menu.luan	Thu May 15 11:03:48 2025 -0600
@@ -223,6 +223,15 @@
 					}
 				}
 			}
+			new_menu{
+				text = "Window"
+				menu_items = {
+					new_menu_item{
+						text = "Duplicate Window"
+						action_listener = action_listener(window.duplicate)
+					}
+				}
+			}
 		}
 	}
 	window.frame.set_menu_bar(menu_bar)
--- a/src/luan_editor/window.luan	Mon Apr 21 13:07:29 2025 -0600
+++ b/src/luan_editor/window.luan	Thu May 15 11:03:48 2025 -0600
@@ -57,7 +57,7 @@
 	config_file.write_text( stringify(config).."\n" )
 end
 
-local function new_window(file)
+local function new_window(file,document)
 	local window = {}
 	window.has_file = file~=nil and file.is_file()
 	local text_area = new_text_area{
@@ -69,7 +69,9 @@
 	}
 	window.text_area = text_area
 	local title = file and file.canonical().to_string() or "new"
-	if file ~= nil then
+	if document ~= nil then
+		text_area.document = document
+	elseif file ~= nil then
 		local document = documents[title]
 		if document == nil then
 			documents[title] = text_area.document
@@ -239,6 +241,10 @@
 		config.tab_size = tab_size
 		save_config()
 	end
+	function window.duplicate()
+		local new = new_window(file,text_area.document)
+		new.text_area.set_selection( text_area.get_selection() )
+	end
 	add_menu_bar(window)
 	frame.pack()
 	if config.location ~= nil then
@@ -247,6 +253,7 @@
 	frame.visible = true
 	text_area.request_focus_in_window()
 	n_windows = n_windows + 1
+	return window
 end
 
 return new_window