English main discussion
Offline
Posts: 1 Joined: Sun Jul 26, 2015 12:08 pm
Post
by sinilill » Sun Jul 26, 2015 12:55 pm
Hi, I wan't to toggle the first character of the currently selected line.
If the first chracter of the line is # then it should remove the chracter and when it's not the first character, then it should write # as the first character.
Thanks
Offline
Posts: 1949 Joined: Sat Mar 06, 2010 7:40 pm
Location: Poland
Post
by KDJ » Sun Jul 26, 2015 3:52 pm
sinilill
Script :
ToggleFirstCharInLine.js ToggleFirstCharInLine.js
Code: Select all
var hEditWnd = AkelPad.GetEditWnd();
var nOffset1;
var nOffset2;
var aLine;
var sChar;
var i;
if (hEditWnd)
{
nOffset1 = AkelPad.SendMessage(hEditWnd, 3138 /*AEM_GETRICHOFFSET*/, 18 /*AEGI_WRAPLINEBEGIN*/, AkelPad.GetSelStart());
nOffset2 = AkelPad.SendMessage(hEditWnd, 3138 /*AEM_GETRICHOFFSET*/, 19 /*AEGI_WRAPLINEEND*/, AkelPad.GetSelEnd());
aLine = AkelPad.GetTextRange(nOffset1, nOffset2).split("\r");
sChar = "#";
for (i = 0; i < aLine.length; ++i)
{
if (aLine[i].charAt(0) == sChar)
aLine[i] = aLine[i].substr(1);
else
aLine[i] = sChar + aLine[i];
}
AkelPad.SetSel(nOffset1, nOffset2);
AkelPad.ReplaceSel(aLine.join("\r"), -1 /*RST_SELECT*/);
}