anchor.diff:  function TKMMemo.KeyDown(Key: Word; Shift: TShiftState): Boolean;
     //Move cursor vertically (change cursor row)
     procedure MoveCursorVertically(aRowIncrement: Integer);
  -  var CursorPointPos: TKMPoint;
  -      NewCursorPosY: Integer;
  -      SrcLineText, DestLineText: UnicodeString;
  -  begin
  -    CursorPointPos := LinearToPointPos(CursorPos);
  -    NewCursorPosY := EnsureRange(CursorPointPos.Y + aRowIncrement, 0, fItems.Count-1);
  -    if NewCursorPosY <> CursorPointPos.Y then
  +  var
  +    cursorPointPos: TKMPoint;
  +    newCursorPosY: Integer;
  +    srcLineText, destLineText: UnicodeString;
  +  begin
  +    cursorPointPos := LinearToPointPos(CursorPos);
  +    newCursorPosY := EnsureRange(cursorPointPos.Y + aRowIncrement, 0, fItems.Count-1);
  +    if newCursorPosY <> cursorPointPos.Y then
       begin
         // Because we don't use monospaces fonts, then its better to find proper column, which depends of text width in px
  -      SrcLineText := GetNoColorMarkupText(Copy(fItems[CursorPointPos.Y], 1, CursorPointPos.X));
  -      DestLineText := GetNoColorMarkupText(fItems[NewCursorPosY]);
  +      srcLineText := GetNoColorMarkupText(Copy(fItems[cursorPointPos.Y], 1, cursorPointPos.X));
  +      destLineText := GetNoColorMarkupText(fItems[newCursorPosY]);
         //Use 'rounding' version of CharsThatFit to get more precise position
  -      CursorPointPos.X := gRes.Fonts[fFont].CharsThatFit(DestLineText, gRes.Fonts[fFont].GetTextSize(SrcLineText).X, True);
  -      CursorPos := PointToLinearPos(CursorPointPos.X, NewCursorPosY);
  +      cursorPointPos.X := gRes.Fonts[fFont].CharsThatFit(destLineText, gRes.Fonts[fFont].GetTextSize(srcLineText).X, True);
  +      CursorPos := PointToLinearPos(cursorPointPos.X, newCursorPosY);
         // Update scroll position, if needed
  -      if TopIndex > NewCursorPosY then
  -        TopIndex := NewCursorPosY
  -      else if TopIndex < NewCursorPosY - GetVisibleRows + 1 then
  -        TopIndex := NewCursorPosY - GetVisibleRows + 1;
  +      if TopIndex > newCursorPosY then
  +        TopIndex := newCursorPosY
  +      else if TopIndex < newCursorPosY - GetVisibleRows + 1 then
  +        TopIndex := newCursorPosY - GetVisibleRows + 1;
       end;
     end;
   
     procedure MoveCursorVerticallyNUpdateSelections(aRowIncrement: Integer);
  -  var OldCursorPos: Integer;
  -  begin
  -    OldCursorPos := CursorPos;
  +  var
  +    oldCursorPos: Integer;
  +  begin
  +    oldCursorPos := CursorPos;
       MoveCursorVertically(aRowIncrement);
  -    UpdateSelection(OldCursorPos);
  -  end;
  -
  -var OldCursorPos: Integer;
  +    UpdateSelection(oldCursorPos);
  +  end;
  +
  +var
  +  oldCursorPos: Integer;
   begin
     Result := KeyEventHandled(Key, Shift);
     if inherited KeyDown(Key, Shift) then Exit;
  
positive.code: ﻿unit KM_Controls;
  {$I KaM_Remake.inc}
  interface
  uses
  
negative.code:   // Update Focus now, because we need to focus on MouseDown, not on MouseUp as by default for all controls
    MasterParent.fMasterControl.UpdateFocus(Self);
  
    oldCursorPos := CursorPos;
    CursorPos := GetCursorPosAt(X, Y);
  
    if Focusable then
    begin
      //Try select on Shift + LMB click
      if (oldCursorPos <> -1) and (Shift = [ssLeft, ssShift]) then
        UpdateSelection(oldCursorPos)
      else begin
        ResetSelection;
      end;
  