function init() {
  console.log('Loaded');
  var cmdline = document.getElementById('cmdline');
  cmdline.oninput = readChar;
}

function readChar(evt) {
  var cmd = evt.currentTarget.value;
  var c = cmd.slice(-1);
  console.log('Read a character: ' + c);
  // Example character dependent processing: ignore 'd'
  if (c === 'd') {
    evt.currentTarget.value = cmd.slice(0, -1); 
  }
}

@@ -162,35 +162,116 @@
 d = evt.
-currentTarget.value
+target.value;%0A  var startInd = evt.target.selectionStart - 1;%0A  var endInd = evt.target.selectionEnd
 ;%0A  var 
@@ -284,18 +284,32 @@
 d.slice(
--1
+startInd, endInd
 );%0A  con
@@ -431,16 +431,9 @@
 evt.
-currentT
+t
 arge
@@ -459,13 +459,121 @@
 (0, 
--1); 
+startInd) + cmd.slice(endInd); %0A    evt.target.selectionStart = startInd;%0A    evt.target.selectionEnd = startInd;
 %0A  %7D

Allow editing mid-string.