3 textarea=document.getElementsByTagName('textarea')[0];
6 function getNewlinePos_back(text,pos){
7 while(pos>=0 && text.charAt(pos)!='\n') pos--;
11 function getNewlinePos_forth(text,pos){
12 let len = text.length;
13 while(pos<len && text.charAt(pos)!='\n') pos++;
17 function deleteLine(ta){
19 let lStart = getNewlinePos_back(text,ta.selectionStart-1);
20 let lEnd = getNewlinePos_forth(text,ta.selectionEnd);
21 ta.value = text.substring(0,lStart+1) + text.substring(lEnd+1);
22 ta.selectionStart = ta.selectionEnd = lStart +1;
28 let start = ta.selectionStart;
29 let end = ta.selectionEnd;
30 let lStart = getNewlinePos_back(text,start-1);
31 let lEnd = getNewlinePos_forth(text,end);
32 let prevS = getNewlinePos_back(text,lStart-1);
33 ta.value = text.substring(0,prevS+1)+text.substring(lStart+1,lEnd+1)+
34 text.substring(prevS+1,lStart+1) + text.substring(lEnd+1);
35 ta.selectionStart = start - (lStart - prevS);
36 ta.selectionEnd = end - (lStart - prevS);
40 function move2Top(ta){
42 let start = ta.selectionStart;
43 let end = ta.selectionEnd;
44 let lStart = getNewlinePos_back(text,start-1);
45 let lEnd = getNewlinePos_forth(text,end);
46 ta.value = text.substring(lStart+1,lEnd+1)+text.substring(0,lStart+1)+
47 text.substring(lEnd+1);
48 ta.selectionStart = start - lStart-1;
49 ta.selectionEnd = end - lStart-1;
53 function move2Bottom(ta){
55 let start = ta.selectionStart;
56 let end = ta.selectionEnd;
57 let lStart = getNewlinePos_back(text,start-1);
58 let lEnd = getNewlinePos_forth(text,end);
59 ta.value = text.substring(0,lStart+1)+text.substring(lEnd+1)+
60 text.substring(lStart+1,lEnd+1);
61 ta.selectionStart = start + text.length - lEnd-1;
62 ta.selectionEnd = end + text.length - lEnd-1;
66 function moveDown(ta){
68 let start = ta.selectionStart;
69 let end = ta.selectionEnd;
70 let lStart = getNewlinePos_back(text,start-1);
71 let lEnd = getNewlinePos_forth(text,end);
72 let nextE = getNewlinePos_forth(text,lEnd+1);
73 ta.value = text.substring(0,lStart+1) + text.substring(lEnd+1,nextE+1) +
74 text.substring(lStart+1,lEnd+1)+text.substring(nextE+1);
75 ta.selectionStart = start + (nextE - lEnd);
76 ta.selectionEnd = end + (nextE - lEnd);
81 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);
85 save(location.pathname);