1

I'm trying to create a Brainfuck IDE with Electron JS. The text-editing part is a <textarea> HTML element.

Right now, when I press Ctrl+Backspace the entire script gets deleted because of what is considered a "word".

How can I change the behavior of Ctrl+Backspace? Is it a Chrome thing, or a JS/Electron thing, or an HTML thing, or a CSS thing?


I would like for each of the 8 Brainfuck characters to be treated as a word. With this behavior, a script that looks like this:

>>><<<+++---...,,,[[[]]]

would be completely deleted in 8 strokes of Ctrl+Backspace. Each block of 3 of the same character is a "word".

Nelson
  • 922
  • 1
  • 9
  • 23
  • Not a direct answer, but you might try https://stackoverflow.com/questions/7295508/javascript-capture-browser-shortcuts-ctrlt-n-w/7296303#7296303 to see if you can override or preventDefault – mckuok Mar 26 '18 at 20:39

1 Answers1

1

Just prevent the default behavior when a Ctrl+Backspace is pressed:

var ta = document.getElementById("ta");

ta.addEventListener("keydown", function(ev) {       // when a keydown event happens in the textarea
  if(ev.ctrlKey && ev.keyCode === 8) {              // check if control key is pressed along with the backspace (key code 8)
    ev.preventDefault();                            // if so, prevent the default behavior of this event
  }
});
<textarea id="ta"></textarea>

Note: After you prevent the default behavior, you can do whatever you like (add some text at the current cursor, delete some characters, ... anything you want).

ibrahim mahrir
  • 31,174
  • 5
  • 48
  • 73
  • 1
    I wanted to not have to reinvent the wheel by re-writing the ctrl+backspace behavior to be how I wanted it, but I just had to do it anyways. Thanks for your answer. – Nelson Mar 27 '18 at 19:20