TextboxでScrapboxのようにブラケットの入力補助
code:script.js
function ComplementSymbol(e,obj){
//ブラケットの入力補助
if(!(e.keyCode === 219 && !(e.shiftKey)) ){ return; }
e.preventDefault();
const selectpoint = obj.selectionStart;
const endpoint = obj.selectionEnd;
//選択位置でテキストを分割して、前と後ろにとを挿入する obj.value = obj.value.substring(0, selectpoint) + " + obj.value.substring(selectpoint,endpoint) + "" + obj.value.substring(endpoint) ;
obj.setSelectionRange(selectpoint +1,endpoint + 1);
}
これまでString.substrを使っていたが、非推奨らしいのでsubstringを使うようにした。