:: MVP ::
|
|
:: RSS ::
|
|
|
Как организовать замену в тексте?
uses
BCEditor.Types;
procedure TForm1.BCEditor1ReplaceText(ASender: TObject; const ASearch,
AReplace: string; ALine, AColumn: Integer; ADeleteLine: Boolean;
var AAction: TBCEditorReplaceAction);
const
s = 'Заменить %s на %s?';
begin
case MessageDlg(Format(s, [ASearch, AReplace]), mtConfirmation, [mbYes, mbYesToAll, mbIgnore, mbCancel], 0) of
mrYes: begin
AAction := raReplace;
Exit;
end;
mrYesToAll: AAction := raReplaceAll;
mrIgnore: AAction := raSkip;
mrCancel: AAction := raCancel;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
BCEditor1.Replace.SetOption(roPrompt, True);
BCEditor1.ReplaceText('SearchText', 'ReplaceText');
BCEditor1.SetFocus;
end;
|
Как проверить, есть ли в редакторе выделенный текст?
// Способ первый
procedure TForm1.Button1Click(Sender: TObject);
begin
case BCEditor1.SelectionAvailable of
True: ShowMessage('Есть выделенный текст');
False: ShowMessage('Нет выделенныого текста');
end;
end;
// Способ второй
procedure TForm1.Button1Click(Sender: TObject);
begin
case BCEditor1.SelectionLength > 0 of
True: ShowMessage('Есть выделенный текст');
False: ShowMessage('Нет выделенныого текста');
end;
end;
// Способ третий
procedure TForm1.Button1Click(Sender: TObject);
begin
case BCEditor1.SelectedText <> '' of
True: ShowMessage('Есть выделенный текст');
False: ShowMessage('Нет выделенныого текста');
end;
end;
|
Как определить границы выделенного текста?
// Способ первый
procedure TForm1.Button1Click(Sender: TObject);
begin
with BCEditor1 do
ShowMessage(Format('%d - %d', [SelectionStart, SelectionStart + SelectionLength]));
end;
// Способ второй
procedure TForm1.Button1Click(Sender: TObject);
begin
with BCEditor1 do
ShowMessage(
Format('%d:%d - %d:%d',
[SelectionBeginPosition.Line, SelectionBeginPosition.Char,
SelectionEndPosition.Line, SelectionEndPosition.Char])
);
end;
|
Как переключать режим выделения?
procedure TForm1.Button1Click(Sender: TObject);
begin
BCEditor1.Selection.Mode := smColumn;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
BCEditor1.Selection.Mode := smNormal;
end;
|
Как реализовать поддержку блочного режима выделения?
uses
BCEditor.Types, BCEditor.Editor.Utils;
var
NewPosition: TBCEditorDisplayPosition = (Column: -1; Row: -1);
StartPosition: TBCEditorDisplayPosition = (Column: -1; Row: -1);
function CtrlDown: Boolean;
begin
Result := (GetAsyncKeyState(VK_CONTROL) shr 16) and 1 = 1;
end;
function ShiftDown: Boolean;
begin
Result := (GetAsyncKeyState(VK_SHIFT) shr 16) and 1 = 1;
end;
function AltDown: Boolean;
begin
Result := (GetAsyncKeyState(VK_MENU) shr 16) and 1 = 1;
end;
procedure TForm1.BCEditor1CaretChanged(ASender: TObject; X, Y: Integer);
begin
if not AltDown then
begin
NewPosition := BCEditor1.DisplayCaretPosition;
StartPosition := BCEditor1.DisplayCaretPosition;
end;
end;
procedure TForm1.BCEditor1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (ssAlt in Shift) and (ssShift in Shift) then
begin
BCEditor1.Selection.Mode := smColumn;
BCEditor1.SelectionBeginPosition := GetTextPosition(StartPosition.Column, StartPosition.Row-1);
case Key of
VK_LEFT: BCEditor1.DisplayCaretX := BCEditor1.DisplayCaretX - 1;
VK_RIGHT: BCEditor1.DisplayCaretX := BCEditor1.DisplayCaretX + 1;
VK_UP: BCEditor1.DisplayCaretY := BCEditor1.DisplayCaretY - 1;
VK_DOWN: BCEditor1.DisplayCaretY := BCEditor1.DisplayCaretY + 1;
else
NewPosition := BCEditor1.DisplayCaretPosition;
StartPosition := BCEditor1.DisplayCaretPosition;
end;
BCEditor1.SelectionEndPosition := GetTextPosition(BCEditor1.DisplayCaretX, BCEditor1.DisplayCaretY-1);
end;
end;
procedure TForm1.BCEditor1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if ssAlt in Shift then
begin
NewPosition.Column := BCEditor1.PixelsToTextPosition(X, Y).Char;
NewPosition.Row := BCEditor1.PixelsToTextPosition(X, Y).Line+1;
StartPosition.Column := BCEditor1.PixelsToTextPosition(X, Y).Char;
StartPosition.Row := BCEditor1.PixelsToTextPosition(X, Y).Line+1;
end;
if not BCEditor1.IsTextPositionInSelection(BCEditor1.PixelsToTextPosition(X, Y)) then
begin
BCEditor1.SelectionEndPosition := BCEditor1.SelectionBeginPosition;
BCEditor1.Selection.Mode := smNormal;
end
else
if BCEditor1.Selection.Mode = smNormal then
BCEditor1.Cursor := crDrag;
end;
procedure TForm1.BCEditor1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if ssAlt in Shift then
begin
BCEditor1.Selection.Mode := smColumn;
BCEditor1.SelectionBeginPosition := GetTextPosition(StartPosition.Column, StartPosition.Row-1);
BCEditor1.SelectionEndPosition := GetTextPosition(BCEditor1.DisplayCaretX, BCEditor1.DisplayCaretY-1);
end;
end;
procedure TForm1.BCEditor1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if (BCEditor1.Selection.Mode = smNormal) and (BCEditor1.Cursor = crDrag) then
BCEditor1.Cursor := crDefault;
end;
|
При использовании материала - ссылка на сайт обязательна
|
|