[geany/geany] 535b7a: Copy selected text only (when present) for Document->Clone
Nick Treleaven
git-noreply at geany.org
Fri Nov 23 15:39:50 UTC 2012
Branch: refs/heads/master
Author: Nick Treleaven <nick.treleaven at btinternet.com>
Committer: Nick Treleaven <nick.treleaven at btinternet.com>
Date: Fri, 23 Nov 2012 15:39:50 UTC
Commit: 535b7a6b6e2c0b8e536a7e6d6ce82db92e06c8c1
https://github.com/geany/geany/commit/535b7a6b6e2c0b8e536a7e6d6ce82db92e06c8c1
Log Message:
-----------
Copy selected text only (when present) for Document->Clone
Modified Paths:
--------------
doc/geany.txt
src/document.c
Modified: doc/geany.txt
5 files changed, 3 insertions(+), 2 deletions(-)
===================================================================
@@ -568,8 +568,9 @@ shortcuts including for Most-Recently-Used document switching.
Cloning documents
^^^^^^^^^^^^^^^^^
The `Document->Clone` menu item copies the current document's text,
-cursor position and properties into a new untitled document. This
-can be useful when making temporary copies of text or for creating
+cursor position and properties into a new untitled document. If
+there is a selection, only the selected text is copied. This can be
+useful when making temporary copies of text or for creating
documents with similar or identical contents.
Modified: src/document.c
11 files changed, 7 insertions(+), 4 deletions(-)
===================================================================
@@ -2739,17 +2739,20 @@ GeanyDocument *document_index(gint idx)
/* create a new file and copy file content and properties */
G_MODULE_EXPORT void on_clone1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
- gint len;
gchar *text;
GeanyDocument *doc;
GeanyDocument *old_doc = document_get_current();
+ ScintillaObject *old_sci;
if (!old_doc)
return;
- len = sci_get_length(old_doc->editor->sci) + 1;
- text = (gchar*) g_malloc(len);
- sci_get_text(old_doc->editor->sci, len, text);
+ old_sci = old_doc->editor->sci;
+ if (sci_has_selection(old_sci))
+ text = sci_get_selection_contents(old_sci);
+ else
+ text = sci_get_contents(old_sci, -1);
+
doc = document_new_file(NULL, old_doc->file_type, text);
g_free(text);
document_set_text_changed(doc, TRUE);
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: TBD).
More information about the Commits
mailing list