Permalink
Browse files

Correctly update caret after insert + improve insertNoScroll()

Based on code from built-in SearchReplace.js
See http://akelpad.sourceforge.net/forum/viewtopic.php?p=23254#23254
  • Loading branch information...
Infocatcher committed Dec 15, 2013
1 parent 8115b63 commit d6eda6fbaf318ed8486bfa27e01a999666496633
Showing with 28 additions and 13 deletions.
  1. +28 −13 toggleComments.js
View
@@ -1108,20 +1108,39 @@ function parseContent(method) {
ro && AkelPad.MessageBox(hMainWnd, insData.str, dialogTitle + _localize(" :: Read only"), 64 /*MB_ICONINFORMATION*/);
}
function insertNoScroll(str, selBefore, selAfter) {
//~ todo: save horizontal scroll?
var lpPoint = AkelPad.MemAlloc(8 /*sizeof(POINT)*/);
if(!lpPoint)
return;
setRedraw(hWndEdit, false);
AkelPad.SendMessage(hWndEdit, 1245 /*EM_GETSCROLLPOS*/, 0, lpPoint);
var nFirstLine = saveLineScroll(hWndEdit);
selBefore && AkelPad.SetSel(selBefore[0], selBefore[1]);
AkelPad.ReplaceSel(str);
selAfter && AkelPad.SetSel(selAfter[0], selAfter[1]);
AkelPad.SendMessage(hWndEdit, 1246 /*EM_SETSCROLLPOS*/, 0, lpPoint);
setRedraw(hWndEdit, true);
AkelPad.MemFree(lpPoint);
restoreLineScroll(hWndEdit, nFirstLine);
}
// From Instructor's SearchReplace.js
function saveLineScroll(hWnd)
{
AkelPad.SendMessage(hWnd, 11 /*WM_SETREDRAW*/, false, 0);
return AkelPad.SendMessage(hWnd, 3129 /*AEM_GETLINENUMBER*/, 4 /*AEGL_FIRSTVISIBLELINE*/, 0);
}
function restoreLineScroll(hWnd, nBeforeLine)
{
if (AkelPad.SendMessage(hWnd, 3129 /*AEM_GETLINENUMBER*/, 4 /*AEGL_FIRSTVISIBLELINE*/, 0) != nBeforeLine)
{
var lpScrollPos;
var nPosY=AkelPad.SendMessage(hWnd, 3198 /*AEM_VPOSFROMLINE*/, 0 /*AECT_GLOBAL*/, nBeforeLine);
if (lpScrollPos=AkelPad.MemAlloc(_X64?16:8 /*sizeof(POINT64)*/))
{
AkelPad.MemCopy(lpScrollPos, -1, 2 /*DT_QWORD*/);
AkelPad.MemCopy(lpScrollPos + (_X64?8:4), nPosY, 2 /*DT_QWORD*/);
AkelPad.SendMessage(hWnd, 3180 /*AEM_SETSCROLLPOS*/, 0, lpScrollPos);
AkelPad.MemFree(lpScrollPos);
}
}
AkelPad.SendMessage(hWnd, 3377 /*AEM_UPDATECARET*/, 0, 0);
AkelPad.SendMessage(hWnd, 11 /*WM_SETREDRAW*/, true, 0);
oSys.Call("user32::InvalidateRect", hWnd, 0, true);
}
function getCurrentExt() {
@@ -1190,10 +1209,6 @@ function getCurrentExt() {
return [ext, cmmSet];
}
function setRedraw(hWnd, bRedraw) {
AkelPad.SendMessage(hWnd, 11 /*WM_SETREDRAW*/, bRedraw, 0);
bRedraw && oSys.Call("user32::InvalidateRect", hWnd, 0, true);
}
function getArg(argName, defaultVal) {
var args = {};
for(var i = 0, argsCount = WScript.Arguments.length; i < argsCount; i++)

0 comments on commit d6eda6f

Please sign in to comment.