1. backend key * * Replace the original backspace function of sourceinsight (hopefully) * Added support for double-byte Chinese characters. When deleting a Chinese character, you can also delete the high byte of the Chinese character to alleviate the problem of half a Chinese character. * Automatically corrected the cursor in the middle of a Chinese character * * Installation: * ① Copy the file to the sourceinsight installation directory; * ② Project → open project: Open the base project; * ③ Add the copied superbackspace. Em to the base project; * ④ Restart sourceinsight; * ⑤ Options → key assignments, bind MARCO: superbackspace to the backspace key; * ⑥ Enjoy !! * * This program is free software; you can redistribute it and/or modify * It under the terms of the GNU General Public License as published * The Free Software Foundation; either version 2 of the license, or * (At your option) any later version. * * This program is distributed in the hope that it will be useful, * But without any warranty; without even the implied warranty * Merchantability or fitness for a special purpose. See * GNU General Public License for more details. * * You shoshould have written ed a copy of the GNU General Public License * Along with this program; if not, write to the Free Software * Foundation, inc., 59 temple place, Suite 330, Boston, MA 02111-1307 USA */ Macro superbackspace () { Hwnd = getcurrentwnd (); Hbuf = getcurrentbuf (); If (hbuf = 0) Stop; // empty Buffer // Get current cursor postion IPOs = getwndselichfirst (hwnd ); // Get current line number Ln = getbuflncur (hbuf ); If (getbufseltext (hbuf )! = "") | (Getwndsellnfirst (hwnd )! = Getwndsellnlast (hwnd ))){ // Something. was selected, del Selection Setbufseltext (hbuf, ""); // stupid & buggy sourceinsight // Del "" Superbackspace (1 ); Stop; } // Copy current line TEXT = getbufline (hbuf, LN ); // Get String Length Len = strlen (text ); // If the cursor is at the start of line, combine with Prev line If (IPOs = 0 | Len = 0 ){ If (LN <= 0) Stop; // top of File Ln = ln-1; // do not use "ln --" for compatibility with older versions Prevline = getbufline (hbuf, LN ); Prevlen = strlen (prevline ); // Combine two lines TEXT = CAT (prevline, text ); // Del two lines Delbufline (hbuf, LN ); Delbufline (hbuf, LN ); // Insert the combined one Insbufline (hbuf, LN, text ); // Set the cursor position Setbufins (hbuf, LN, prevlen ); Stop; } Num = 1; // del one char If (IPOs> = 1 ){ // Process Chinese Character I = IPOs; Count = 0; While (asciifromchar (Text [I-1]) >=160 ){ I = I-1; Count = count + 1; If (I = 0) Break; } If (count> 0 ){ // I think it might be a two-Byte Character Num = 2; // This idiot does not support mod and bitwise operators If (count/2*2! = Count) & (IPOs <Len )) IPOs = IPOs + 1; // adjust cursor position } } // Keeping safe If (IPOs-num <0) Num = IPOs; // Del char (s) TEXT = CAT (strmid (text, 0, IPOs-num), strmid (text, IPOs, Len )); Delbufline (hbuf, LN ); Insbufline (hbuf, LN, text ); Setbufins (hbuf, LN, IPOs-num ); Stop; } Refer to the CHM help document above and in sourceinsight; Disadvantages: (1) Moving arrows also record historical operation steps, which should be avoided; (2) functions are not organized and redundant; 2. delete key -- superdelete. Em Macro superdelete () { Hwnd = getcurrentwnd (); Hbuf = getcurrentbuf (); If (hbuf = 0) Stop; // empty Buffer // Get current cursor postion IPOs = getwndselichfirst (hwnd ); // Get current line number Ln = getbuflncur (hbuf ); If (getbufseltext (hbuf )! = "") | (Getwndsellnfirst (hwnd )! = Getwndsellnlast (hwnd ))){ // Something. was selected, del Selection Setbufseltext (hbuf, ""); // stupid & buggy sourceinsight // Del "" Superdelete (1 ); Stop; } // Copy current line TEXT = getbufline (hbuf, LN ); // Get String Length Len = strlen (text );
If (IPOs = Len | Len = 0 ){ Totalln = getbuflinecount (hbuf ); Lasttext = getbufline (hbuf, totalLn-1 ); Lastlen = strlen (lasttext ); If (IPOs = lastlen) // end of File Stop; Ln = ln + 1; // do not use "ln --" for compatibility with older versions Nextline = getbufline (hbuf, LN ); Nextlen = strlen (nextline ); // Combine two lines TEXT = CAT (text, nextline ); // Del two lines Delbufline (hbuf, ln-1 ); Delbufline (hbuf, ln-1 ); // Insert the combined one Insbufline (hbuf, ln-1, text ); // Set the cursor position Setbufins (hbuf, ln-1, Len ); Stop; } Num = 1; // del one char If (IPOs> 0 ){ // Process Chinese Character I = IPOs; Count = 0; While (asciifromchar (Text [I-1])> = 160 ){ I = I-1; Count = count + 1; If (I = 0) Break; } If (count> 0 ){ // I think it might be a two-Byte Character Num = 2; // This idiot does not support mod and bitwise operators If (count/2*2! = Count) | COUNT = 0) & (IPOs <len-1 )) IPOs = IPOs + 1; // adjust cursor position } // Keeping safe If (IPOs-num <0) Num = IPOs; } Else { I = IPOs; Count = 0; While (asciifromchar (Text [I]) & gt; = 160 ){ I = I + 1; Count = count + 1; If (I = len-1) Break; } If (count> 0 ){ Num = 2; } }
TEXT = CAT (strmid (text, 0, IPOs), strmid (text, IPOs + num, Len )); Delbufline (hbuf, LN ); Insbufline (hbuf, LN, text ); Setbufins (hbuf, LN, IPOs ); Stop; } 3. Shift left key -- supercursorleft. Em Macro iscomplexcharacter () { Hwnd = getcurrentwnd (); Hbuf = getcurrentbuf (); If (hbuf = 0) Return 0; // Current location Pos = getwndselichfirst (hwnd ); // Current number of rows Ln = getbuflncur (hbuf ); // Obtain the current row TEXT = getbufline (hbuf, LN ); // Obtain the length of the current row Len = strlen (text ); // Calculate the number of Chinese characters from the beginning If (Pos> 0) { I = Pos; Count = 0; While (asciifromchar (Text [I-1])> = 160) { I = I-1; Count = count + 1; If (I = 0) Break; } If (count/2) * 2 = count | COUNT = 0) Return 0; Else Return 1; } Return 0; } Macro moveleft () { Hwnd = getcurrentwnd (); Hbuf = getcurrentbuf (); If (hbuf = 0) Stop; // empty Buffer
Ln = getbuflncur (hbuf ); IPOs = getwndselichfirst (hwnd ); If (getbufseltext (hbuf )! = "" | (IPOs = 0 & Ln = 0) // if there are 0th rows or lines of selected text, do not move { Setbufins (hbuf, LN, IPOs ); Stop; }
If (IPOs = 0) { Preline = getbufline (hbuf, ln-1 ); Setbufins (hbuf, ln-1, strlen (preline)-1 ); } Else { Setbufins (hbuf, LN, ipos-1 ); } } Macro supercursorleft () { Moveleft (); If (iscomplexcharacter ()) Moveleft (); } 4. Right Shift key -- supercursorright. Em Macro moveright () { Hwnd = getcurrentwnd (); Hbuf = getcurrentbuf (); If (hbuf = 0) Stop; // empty Buffer Ln = getbuflncur (hbuf ); IPOs = getwndselichfirst (hwnd ); Totalln = getbuflinecount (hbuf ); TEXT = getbufline (hbuf, LN ); If (getbufseltext (hbuf )! = "") // Select text { IPOs = getwndselichlim (hwnd ); Ln = getwndsellnlast (hwnd ); Setbufins (hbuf, LN, IPOs ); Stop; } If (IPOs = strlen (text)-1 & Ln = totalLn-1) // last line Stop; If (IPOs = strlen (text )) { Setbufins (hbuf, LN + 1, 0 ); } Else { Setbufins (hbuf, LN, IPOs + 1 ); } } Macro supercursorright () { Moveright (); If (iscomplexcharacter () // defined in supercursorleft. Em Moveright (); } 5. Shift + Right Shift key -- shiftcursorright. Em Macro isshiftrightcomplexcharacter () { Hwnd = getcurrentwnd (); Hbuf = getcurrentbuf (); If (hbuf = 0) Return 0; Selrec = getwndsel (hwnd ); Pos = selrec. ichlim; Ln = selrec. lnlast; TEXT = getbufline (hbuf, LN ); Len = strlen (text ); If (LEN = 0 | Len <POS) Return 1; // MSG ("@ Len @; @ POS @;"); If (Pos> 0) { I = Pos; Count = 0; While (asciifromchar (Text [I-1])> = 160) { I = I-1; Count = count + 1; If (I = 0) Break; } If (count/2) * 2 = count | COUNT = 0) Return 0; Else Return 1; } Return 0; } Macro shiftmoveright () { Hwnd = getcurrentwnd (); Hbuf = getcurrentbuf (); If (hbuf = 0) Stop;
Ln = getbuflncur (hbuf ); IPOs = getwndselichfirst (hwnd ); Totalln = getbuflinecount (hbuf ); TEXT = getbufline (hbuf, LN ); Selrec = getwndsel (hwnd ); Curlen = getbuflinelength (hbuf, selrec. lnlast ); If (selrec. ichlim = curlen + 1 | curlen = 0) { If (selrec. lnlast = totalln-1) Stop; Selrec. lnlast = selrec. lnlast + 1; Selrec. ichlim = 1; Setwndsel (hwnd, selrec ); If (isshiftrightcomplexcharacter ()) Shiftmoveright (); Stop; }
Selrec. ichlim = selrec. ichlim + 1; Setwndsel (hwnd, selrec ); } Macro supershiftcursorright () { If (iscomplexcharacter ()) Supercursorright (); Shiftmoveright (); If (isshiftrightcomplexcharacter ()) Shiftmoveright (); } 6. Shift + Left Shift key -- shiftcursorleft. Em Macro isshiftleftcomplexcharacter () { Hwnd = getcurrentwnd (); Hbuf = getcurrentbuf (); If (hbuf = 0) Return 0; Selrec = getwndsel (hwnd ); Pos = selrec. ichfirst; Ln = selrec. lnfirst; TEXT = getbufline (hbuf, LN ); Len = strlen (text ); If (LEN = 0 | Len <POS) Return 1; // MSG ("@ Len @; @ POS @;"); If (Pos> 0) { I = Pos; Count = 0; While (asciifromchar (Text [I-1])> = 160) { I = I-1; Count = count + 1; If (I = 0) Break; } If (count/2) * 2 = count | COUNT = 0) Return 0; Else Return 1; } Return 0; } Macro shiftmoveleft () { Hwnd = getcurrentwnd (); Hbuf = getcurrentbuf (); If (hbuf = 0) Stop;
Ln = getbuflncur (hbuf ); IPOs = getwndselichfirst (hwnd ); Totalln = getbuflinecount (hbuf ); TEXT = getbufline (hbuf, LN ); Selrec = getwndsel (hwnd ); // Curlen = getbuflinelength (hbuf, selrec. lnfirst ); // MSG ("@ curlen @; @ selrec @"); If (selrec. ichfirst = 0) { If (selrec. lnfirst = 0) Stop;
Selrec. lnfirst = selrec. lnfirst-1; Selrec. ichfirst = getbuflinelength (hbuf, selrec. lnfirst)-1; Setwndsel (hwnd, selrec ); If (isshiftleftcomplexcharacter ()) Shiftmoveleft (); Stop; }
Selrec. ichfirst = selrec. ichFirst-1; Setwndsel (hwnd, selrec ); } Macro supershiftcursorleft () { If (iscomplexcharacter ()) Supercursorleft (); Shiftmoveleft (); If (isshiftleftcomplexcharacter ()) Shiftmoveleft (); } |