diff options
author | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2012-10-19 18:20:31 +0100 |
---|---|---|
committer | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2012-10-19 18:20:31 +0100 |
commit | c76ac77e0d2961bc8f24f8d13ab1cfd5ae9849bc (patch) | |
tree | 3cf2b924111c90a3d00b8e50471e5eac93229614 /examples/apps/ide | |
parent | 23e140b3e1eac87d5f533f42cecfd140a0cdb50b (diff) | |
download | fpGUI-c76ac77e0d2961bc8f24f8d13ab1cfd5ae9849bc.tar.xz |
textedit: Newly implemented GetSelectedText function.
Diffstat (limited to 'examples/apps/ide')
-rw-r--r-- | examples/apps/ide/src/fpg_textedit.pas | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/examples/apps/ide/src/fpg_textedit.pas b/examples/apps/ide/src/fpg_textedit.pas index a5f73fa2..5ae1b52a 100644 --- a/examples/apps/ide/src/fpg_textedit.pas +++ b/examples/apps/ide/src/fpg_textedit.pas @@ -188,6 +188,7 @@ type procedure ScrollTo(X, Y: Integer); procedure GotoLine(ALine: integer); procedure DeleteSelection; + function GetSelectedText: TfpgString; procedure SaveToFile(const AFileName: TfpgString); procedure LoadFromFile(const AFileName: TfpgString); procedure FindText(TextToFind: TfpgString; FindOptions: TfpgFindOptions; Backward: Boolean = False); @@ -2179,6 +2180,59 @@ begin Invalidate; end; +function TfpgBaseTextEdit.GetSelectedText: TfpgString; +var + StartLine, StartPos, EndLine, EndPos, I, LineI: Integer; + FirstPart, LastPart, SLine: string; +begin + Result := ''; + if not FSelected then Exit; + if not FSelected then Exit; + if FSelStartNo > FSelEndNo then + begin + StartLine := FSelEndNo; + StartPos := FSelEndOffs; + EndLine := FSelStartNo; + EndPos := FSelStartOffs; + end + else + begin + if (FSelStartNo = FSelEndNo) and (FSelEndOffs < FSelStartOffs) then + begin + StartLine := FSelStartNo; + StartPos := FSelEndOffs; + EndLine := StartLine; + EndPos := FSelStartOffs; + end + else + begin + StartLine := FSelStartNo; + StartPos := FSelStartOffs; + EndLine := FSelEndNo; + EndPos := FSelEndOffs; + end; + end; + if StartLine > pred(FLines.Count) then Exit; + if EndLine > pred(FLines.Count) then + EndLine := pred(FLines.Count); + SLine := FLines[StartLine]; + if StartLine < EndLine then + begin + FirstPart := Copy(SLine, StartPos + 1, Length(SLine) - StartPos); + SLine := FLines[EndLine]; + if EndPos > Length(SLine) then + EndPos := Length(SLine); + LastPart := Copy(SLine, 1, EndPos); + LineI := StartLine + 1; + Result := FirstPart; + for I := LineI to (EndLine - 1) do + Result := Result + LineEnding + FLines[I]; + Result := Result + LineEnding + LastPart; + end + else + Result := Copy(SLine, StartPos + 1, EndPos - StartPos); +end; + procedure TfpgBaseTextEdit.SaveToFile(const AFileName: TfpgString); var BuffList: TStringList; |