Skip to content

Commit

Permalink
Fixes #564 : Modified nodes could be truncated on saving (with RichTe…
Browse files Browse the repository at this point in the history
…xt 4.1, in XP and W7) [in rare occasions]

Corrects the problem that could arise if we try to replace, with Paste as Text, a selected hyperlink. It is something very unusual, but could happen.

Signed-off-by: Daniel Prado Velasco <dpradov@users.noreply.github.com>
  • Loading branch information
dpradov committed Apr 30, 2017
1 parent 9f28a03 commit 035ab10
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions macros/kn_MacroMng.pas
Expand Up @@ -1716,19 +1716,53 @@ procedure PerformCmdPastePlain( Note: TTabNote;
var
Editor: TTabRichEdit;
i, j: integer;
Ok: Boolean;

function PasteOperationWasOK(StrClp, Selection: WideString): boolean;
var
i, j, n: integer;
begin
Result:= False;
i:= 1;
j:= 1;
n:= Length(StrClp);

if n = Length(Selection) then begin
while (i <= 4) and (i <= n) do begin
if StrClp[i] <> #$A then begin
if StrClp[i] <> Selection[j] then
exit;
Inc(j);
end;
Inc(i);
end;
Result:= True;
end;
end;

begin
Editor:= Note.Editor;
Ok:= True;

if ForcePlainText or Note.PlainText or (ClipOptions.PlainTextMode = clptPlainText) then begin
if StrClp = '' then
StrClp:= ClipboardAsStringW;

if (( ClipOptions.MaxSize > 0 ) and ( length( StrClp ) > ClipOptions.MaxSize )) then
delete( StrClp, succ( ClipOptions.MaxSize ), length( StrClp ));
StrClp:= Trim(StrClp);
Editor.SelTextW := StrClp;
Editor.SelStart := Editor.SelStart + Editor.SelLength - NumberOfLineFeed(StrClp);

if RichEditVersion < 5 then begin
if not PasteOperationWasOK (StrClp, Editor.SelVisibleTextW) then begin
Editor.Undo;
Editor.SelLength:= 0;
Ok:= False;
end;
end;

if Ok then
Editor.SelStart := Editor.SelStart + Editor.SelLength - NumberOfLineFeed(StrClp);

end
else begin
if HTMLClip = '' then
Expand Down

0 comments on commit 035ab10

Please sign in to comment.