garplab / typingtube

24 stars 1 forks source link

【要望】データ作成時の「ルビタグ」をEnterで挿入した際のカーソル位置の移動 #59

Open fire1192 opened 4 years ago

fire1192 commented 4 years ago

現在データ作成時、「ルビタグ」をEnterで挿入した際カーソルが必ず末尾に移動する仕様です。 Enterでショートカットしてるにも関わらず矢印でルビの場所まで移動するか結局マウスを使ってカーソルを移動させる感じでデータを作成しています。 そこで、Enterでルビタグを挿入した際にテキストのカーソルの位置を<rt></rt>の中に移動させるという仕様に変更してほしいです。 検討お願いいたします。

garplab commented 4 years ago

できそうなので、こんど試してみます https://javascript.programmer-reference.com/javascript-setselectionrange/

Toshi7878 commented 4 years ago

function command_ruby() { const start = $('#words').get(0).selectionStart; const end = $('#words').get(0).selectionEnd; if(end - start < 1) { return false; } const text = $('#words').val(); const fix_text = text.slice(0, start) + '' + text.slice(start, end) + '' + text.slice(end, text.length); $('#words').val(fix_text); document.getElementById("words").focus(); document.getElementById("words").setSelectionRange(document.getElementById("words").value.search("")+4, document.getElementById("words").value.search("")+4); }

command_ruby()関数にカーソル移動機能を加えてみました。