// find the node that is supposed to come before this one. vMark := Self; vPosition := fPosition; vMark := vMark.PreviousMark; // assert(Assigned(vMark)); except for beginning and end node. while Assigned(vMark) do begin if vMark.Position < vPosition then Break; vMark := vMark.PreviousMark; end; // => vMark. vPreviousMark := vMark; // find the node that is supposed to come after this one. vMark := Self; vMark := vMark.NextMark; while Assigned(vMark) do begin if vMark.Position > vPosition then Break; vMark := vMark.NextMark; end; // => vMark. vNextMark := vMark; if Self.PreviousMark <> vPreviousMark then begin if Assigned(vPreviousMark) then begin if Assigned(vPreviousMark.NextMark) then vPreviousMark.NextMark.PreviousMark := vPreviousMark; vPreviousMark.NextMark := Self; end; Self.PreviousMark := vPreviousMark; end; if Self.NextMark <> vNextMark then begin if Assigned(vNextMark) then begin if Assigned(vNextMark.PreviousMark) then vNextMark.PreviousMark.NextMark := vNextMark; vNextMark.PreviousMark := Self; end; Self.NextMark := vNextMark; end; { sanity check. } vMark := Self.PreviousMark; while Assigned(vMark) do begin assert(vMark.Position <= vPosition); vMark := vMark.PreviousMark; end; vMark := Self.NextMark; while Assigned(vMark) do begin assert(vMark.Position >= vPosition); vMark := vMark.NextMark; end; //if Assigned(fTextBuffer) then // fTextBuffer.SortMark(Self);