2021-08-28 23:49:58 +00:00
|
|
|
var textarea;
|
2021-09-06 05:54:12 +00:00
|
|
|
onload=function(){
|
|
|
|
textarea=document.getElementsByTagName('textarea')[0];
|
|
|
|
}
|
|
|
|
|
2021-08-28 23:49:58 +00:00
|
|
|
function getNewlinePos_back(text,pos){
|
|
|
|
while(pos>=0 && text.charAt(pos)!='\n') pos--;
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getNewlinePos_forth(text,pos){
|
|
|
|
let len = text.length;
|
|
|
|
while(pos<len && text.charAt(pos)!='\n') pos++;
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteLine(ta){
|
|
|
|
let text = ta.value;
|
|
|
|
let lStart = getNewlinePos_back(text,ta.selectionStart-1);
|
|
|
|
let lEnd = getNewlinePos_forth(text,ta.selectionEnd);
|
|
|
|
ta.value = text.substring(0,lStart+1) + text.substring(lEnd+1);
|
|
|
|
ta.selectionStart = ta.selectionEnd = lStart +1;
|
|
|
|
ta.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
function moveUp(ta){
|
|
|
|
let text = ta.value;
|
|
|
|
let start = ta.selectionStart;
|
|
|
|
let end = ta.selectionEnd;
|
|
|
|
let lStart = getNewlinePos_back(text,start-1);
|
|
|
|
let lEnd = getNewlinePos_forth(text,end);
|
|
|
|
let prevS = getNewlinePos_back(text,lStart-1);
|
|
|
|
ta.value = text.substring(0,prevS+1)+text.substring(lStart+1,lEnd+1)+
|
|
|
|
text.substring(prevS+1,lStart+1) + text.substring(lEnd+1);
|
|
|
|
ta.selectionStart = start - (lStart - prevS);
|
|
|
|
ta.selectionEnd = end - (lStart - prevS);
|
|
|
|
ta.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
function move2Top(ta){
|
|
|
|
let text = ta.value;
|
|
|
|
let start = ta.selectionStart;
|
|
|
|
let end = ta.selectionEnd;
|
|
|
|
let lStart = getNewlinePos_back(text,start-1);
|
|
|
|
let lEnd = getNewlinePos_forth(text,end);
|
|
|
|
ta.value = text.substring(lStart+1,lEnd+1)+text.substring(0,lStart+1)+
|
|
|
|
text.substring(lEnd+1);
|
|
|
|
ta.selectionStart = start - lStart-1;
|
|
|
|
ta.selectionEnd = end - lStart-1;
|
|
|
|
ta.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
function move2Bottom(ta){
|
|
|
|
let text = ta.value;
|
|
|
|
let start = ta.selectionStart;
|
|
|
|
let end = ta.selectionEnd;
|
|
|
|
let lStart = getNewlinePos_back(text,start-1);
|
|
|
|
let lEnd = getNewlinePos_forth(text,end);
|
|
|
|
ta.value = text.substring(0,lStart+1)+text.substring(lEnd+1)+
|
|
|
|
text.substring(lStart+1,lEnd+1);
|
|
|
|
ta.selectionStart = start + text.length - lEnd-1;
|
|
|
|
ta.selectionEnd = end + text.length - lEnd-1;
|
|
|
|
ta.focus();
|
|
|
|
}
|
|
|
|
|
|
|
|
function moveDown(ta){
|
|
|
|
let text = ta.value;
|
|
|
|
let start = ta.selectionStart;
|
|
|
|
let end = ta.selectionEnd;
|
|
|
|
let lStart = getNewlinePos_back(text,start-1);
|
|
|
|
let lEnd = getNewlinePos_forth(text,end);
|
|
|
|
let nextE = getNewlinePos_forth(text,lEnd+1);
|
|
|
|
ta.value = text.substring(0,lStart+1) + text.substring(lEnd+1,nextE+1) +
|
|
|
|
text.substring(lStart+1,lEnd+1)+text.substring(nextE+1);
|
|
|
|
ta.selectionStart = start + (nextE - lEnd);
|
|
|
|
ta.selectionEnd = end + (nextE - lEnd);
|
|
|
|
ta.focus();
|
|
|
|
}
|
|
|
|
|
2022-04-06 09:13:22 +00:00
|
|
|
function save(fn){
|
2021-09-06 05:54:12 +00:00
|
|
|
let u8=new TextEncoder().encode(textarea.value);let r='';for(let i=0;i<u8.byteLength;i++)r+=String.fromCharCode(u8[i]);location.href='i:0l'+fn+':'+btoa(r);
|
2021-08-28 23:49:58 +00:00
|
|
|
}
|
2022-04-06 09:13:22 +00:00
|
|
|
|
|
|
|
function onSave(){
|
|
|
|
save(location.pathname);
|
|
|
|
}
|