GNOME Bugzilla – Bug 766830
Shortcut keys - duplicate
Last modified: 2016-06-17 19:25:21 UTC
trying Ctrl + D to duplicate a line does not work this seems to delete, this is not listed in the shortcut screen, and if thats delete whats duplicate and can that be added to the shortcut search ? Can we duplicate a line yet and what's the keybinding ?
In vim mode you would do `yyp`, but I don't think we have a keybinding for the "gedit" mode (our default mode). Do you know what the duplicate line shortcut is in Gedit?
For a recap: Geany use ctrl+d Sublime Text use ctrl+shift+d Atom use ctrl+shift+d XCode use command+d Eclipse ctrl+alt+up or down Visual Studio, nothing specific With Gedit, ctrl+d is already used to delete a line, but nothing specific to duplicate it Don't forget that under Gtk+, ctrl+shift+d is use to trigger the inspector if activated before ( from the cli or in gsettings )
so if its not currently available can we get it added to default mode, its extremely handy :) ?
We just need to agree on a currently free shortcut to use
Created attachment 328724 [details] [review] Bug 766830 - Shortcut keys - duplicate line Added keybindings for duplicating a line. ctrl+alt+d is added as keyboard shortcut for duplicating a line. Also added the keyboard shortcut in the shortcut window.
Review of attachment 328724 [details] [review]: you need to do the paste part of this *duplicate line* action ::: data/ui/ide-shortcuts-window.ui @@ +215,3 @@ + <property name="visible">1</property> + <property name="accelerator"><ctrl><alt>d</property> + <property name="title" translatable="yes" context="shortcut window">Copy entire line to clipboard</property> Duplicate entire line to clipboard ::: libide/ide-source-view.c @@ +3061,3 @@ + GtkTextView *text_view = (GtkTextView *)self; + GtkTextIter start, end; + g_autofree gchar *line; please always set the g_auto_* macros to NULL @@ +3075,3 @@ + + gtk_text_buffer_get_iter_at_mark (buffer, &start, cursor); + gtk_text_buffer_get_iter_at_mark (buffer, &end, cursor); you can do: end = start @@ +3081,3 @@ + + line = gtk_text_iter_get_text (&start, &end); + strcat(line, "\n"); use the g_strconcat or g_strcat API
Created attachment 328751 [details] [review] Bug 766830 - Shortcut keys - duplicate line Added keybindings for duplicating a line. ctrl+alt+d is added as keyboard shortcut for duplicating a line. Also added the keyboard shortcut in the shortcut window. https://bugzilla.gnome.org/show_bug.cgi?id=766830 Bug 766830 - Shortcut keys - duplicate line Made the duplicate function like that in sublime text. Contents of clipboard arent changed. Changed windows-shortcuts name.
Created attachment 328752 [details] [review] Bug 766830 - Shortcut keys - duplicate line Added keybindings for duplicating a line. ctrl+alt+d is added as keyboard shortcut for duplicating a line. Also added the keyboard shortcut in the shortcut window. https://bugzilla.gnome.org/show_bug.cgi?id=766830 Bug 766830 - Shortcut keys - duplicate line Made the duplicate function like that in sublime text. Contents of clipboard arent changed. Changed windows-shortcuts name. https://bugzilla.gnome.org/show_bug.cgi?id=766830 Had forgotten about setting the g_auto_* macros to NULL.
Created attachment 328859 [details] [review] Bug 766830 - Shortcut keys - duplicate line Added keybindings for duplicating a line. ctrl+alt+d is added as keyboard shortcut for duplicating a line. Also added the keyboard shortcut in the shortcut window. https://bugzilla.gnome.org/show_bug.cgi?id=766830 Bug 766830 - Shortcut keys - duplicate line Made the duplicate function like that in sublime text. Contents of clipboard arent changed. Changed windows-shortcuts name. https://bugzilla.gnome.org/show_bug.cgi?id=766830 Had forgotten about setting the g_auto_* macros to NULL. https://bugzilla.gnome.org/show_bug.cgi?id=766830 Bug 766830 - Shortcut keys - duplicate Changed instances of copy to duplicate. Avoided mem leak.
Review of attachment 328859 [details] [review]: todo: - fix the case where we are on an empty line - take the selection into account - cleanup the commit message, we don't need the development history ::: data/ui/ide-shortcuts-window.ui @@ +215,3 @@ + <property name="visible">1</property> + <property name="accelerator"><ctrl><alt>d</property> + <property name="title" translatable="yes" context="shortcut window">Duplicate entire line to clipboard</property> 'Duplicate current line or selection' is more correct
Created attachment 328903 [details] [review] Bug 766830 - Shortcut keys - duplicate Implemented function to duplicate entire line or selected text using keyboard binding ctrl+alt+d. Also added the keybinding in shortcut window.
Review of attachment 328903 [details] [review]: ::: data/keybindings/default.css @@ -24,2 +24,3 @@ bind "<ctrl>i" { "action" ("view", "goto-line", "") }; bind "<ctrl>asciitilde" { "change-case" (toggle) }; + bind "<ctrl><alt>d" { "duplicate-entire-line" ()}; space before } ::: data/ui/ide-shortcuts-window.ui @@ -211,2 +211,5 @@ </object> </child> + <child> + <object class="GtkShortcutsShortcut"> + <property name="visible">1</property> 1 is fine, I didn't realize everything else was using it in this file. ::: libide/ide-source-view.c @@ -3057,1 +3058,5 @@ static void +ide_source_view_real_duplicate_entire_line (IdeSourceView *self) +{ + GtkTextView *text_view = (GtkTextView *)self; + GtkTextIter start, end; Use "begin" instead of "start" as it clashes with a libc symbol @@ +3079,3 @@ + if (selected) + { + duplicate_line = gtk_text_iter_get_text (&start, &end); The signal is "duplicate-entire-line" yet this only duplicates the selection without adding a \n. Doesn't that seem strange? @@ +3093,3 @@ + { + text = gtk_text_iter_get_text (&start, &end); + duplicate_line = g_strconcat (text, "\n", NULL); I think this is broken on the last line of the file. you'll get "foo" → "foofoo\n". Do an insert of "\n" at end first and then the text (no need to do the concat first).
Created attachment 328908 [details] [review] Bug 766830 - Shortcut keys - duplicate Implemented function to duplicate entire line or selected text using keyboard binding ctrl+alt+d. Also added the keybinding in shortcut window.
Thanks!