View Issue Details

IDProjectCategoryView StatusLast Update
0009221mantisbtfeaturepublic2008-09-17 07:23
ReporterJanko Assigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
Status newResolutionopen 
Summary0009221: Ctrl+Enter == submit in any textarea
Description

It would be great, if I can submit directly in textarea (ex. add new comment) with Ctrl+Enter keyboard combo.

Tagspatch

Activities

Janko

Janko

2008-06-18 10:11

reporter   ~0018130

I'm not a JS-expert, but this works fine in Firefox 2 under GNU/Linux with bugnote add textareas.

var notebox = document.getElementById('bugnote_text') || false;
if (notebox == false) return;

var ctrl = false;
notebox.onkeydown = function(ev) {
if (ev.keyCode == 17) ctrl = true;
if (ev.keyCode == 13 && ctrl == true) {
document.getElementById('bugnote_add_open').firstChild.submit();
ctrl = false;
}
}
notebox.onkeyup = function(ev) {
if (ev.keyCode == 17) ctrl == false;
}

This works only if first child element of div id `bugnote_add_open' is <form> (default theme is good).

bbryant

bbryant

2008-06-26 16:14

reporter   ~0018194

Last edited: 2008-06-26 16:20

I made a few modifications to Janko's submission to apply to all text areas and forms.


var ctrl = false;
var talist = document.getElementsByTagName("textarea");

for (var i = 0; i < talist.length; i++) {
talist[i].onkeydown = function(ev) {
if (ev.which)
ev.keyCode = ev.which;

  if (ev.keyCode == 17)
    ctrl = true;

  else if (ev.keyCode == 13 && ctrl) {
    var parent = this;

    do {
      parent = this.parentNode;
    } while (parent && !parent.submit);

    if (parent)
      parent.submit();
  }
}

talist[i].onkeyup = function(ev) {
  if (ev.which)
    ev.keyCode = ev.which;

  if (ev.keyCode == 17) 
    ctrl = false;
}

}

docuemnt.body.onkeydown = function(ev) {
if (ev.which)
ev.keyCode = ev.which;

if (ev.keyCode == 17)
  ctrl = true;

}

docuemnt.body.onkeyup = function(ev) {
if (ev.which)
ev.keyCode = ev.which;

if (ev.keyCode == 17)
  ctrl = false;

}

Janko

Janko

2008-06-27 07:54

reporter   ~0018200

Hi bbryant,
Great, thanks it's works perfectly!

Janko

Janko

2008-09-17 07:23

reporter   ~0019405

I had latency and race condition problems with the previous solutions. Sometimes if I type too fast, simple "enter" was enough to trigger the event.

So here it the modified version:


var talist = document.getElementsByTagName("textarea");

for (var i = 0; i < talist.length; i++) {
talist[i].onkeydown = function(ev) {
if (ev.ctrlKey == true && ev.keyCode == 13) {
do {
parent = this.parentNode;
} while (parent && !parent.submit);

        if (parent)
            parent.submit();
    }
}

}

Tested under Firefox 2 under GNU/Linux.