keyboard shortcuts for EditSectionPlugin popup

43 views
Skip to first unread message

Yaisog Bonegnasher

unread,
Sep 28, 2012, 8:46:04 AM9/28/12
to tiddly...@googlegroups.com
Since I keep pressing CTRL+Enter and ESC when editing sections in the EditSectionPlugin popup (which doesn't do anything), I added these keyboard shortcuts for "save" and "cancel," respectively.
I'll post my additions in case they can help anyone else. Maybe Eric will even update his plugin some day. I'm not sure this is the ideal way to handle things, as I did neither write the core or the plugin, but it works for me.

Changes in EditSectionPlugin v1.8.1:
in createPanel:
this.showPanel(p,here,ev);
jQuery(f).find("TEXTAREA").focus();
return this.ok(ev);
in initForm:
form.content.value=store.getTiddlerText(tid,''); 
jQuery(form).keydown( function(eventObject) { // add a keyboard handler to the form element
if (eventObject.which == 27) config.macros.editSection.cancel(this,eventObject); // ESC pressed
if (eventObject.which == 13 && eventObject.ctrlKey) config.macros.editSection.saveForm(this,eventObject); // Ctrl-Enter pressed
});
if (version.extensions.TextAreaPlugin) new window.TextAreaResizer(form.content);
in saveForm:
replace
var f=here.form;
with
var f=(here.form ? here.form : here); // check for events attached to the form itself

in cancel:
replace
this.removePanel(here.form.panel);
with
here.form ? this.removePanel(here.form.panel) : this.removePanel(here.panel); // check for events attached to form itself

The keyboard event is attached to the form element. Therefore the called methods saveForm and cancel must be changed to account for the possibility of being called with here referring to the form, not just an element in the form. The textarea element is given focus upon opening the popup so that immediately pressing ESC works (otherwise this event gets sent to the popup window instead of the form).

I hope this is of use to someone,
Yaisog.


Yaisog Bonegnasher

unread,
Nov 8, 2012, 1:41:10 PM11/8/12
to tiddly...@googlegroups.com
I noticed that some of the code is redundant and the changes are fewer if it suffices that the ESC and CTRL-ENTER work while the cursor is in one of the two text fields (and the three buttons are not focused), which is usually the case:

in createPanel:
this.showPanel(p,here,ev);
jQuery(f.content).focus();
return this.ok(ev);

in initForm:
form.content.value=store.getTiddlerText(tid,''); 
jQuery(form.content).add(form.newsection).keydown( function(eventObject) { // add a keyboard handler to the text fields

if (eventObject.which == 27) config.macros.editSection.cancel(this,eventObject); // ESC pressed
if (eventObject.which == 13 && eventObject.ctrlKey) config.macros.editSection.saveForm(this,eventObject); // Ctrl-Enter pressed
});
if (version.extensions.TextAreaPlugin) new window.TextAreaResizer(form.content);
 
saveForm and cancel need not be edited.
 
Yaisog.

Reply all
Reply to author
Forward
0 new messages