position of caret after marking a word/area
position of caret after marking a word/area
After marking a word (sentence).
How can I find out whether the caret stands at the beginning or end of a selected word (sentence).
How can I find out whether the caret stands at the beginning or end of a selected word (sentence).
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Hello Sergey,
thank you for your fast help.
memo.GetSelectionBounds(StartItemNo, StartItemOffs, EndItemNo, EndItemOffs, true);
memoPos:=RVGetLinearCaretPos(memo);
laenge:= length(memo.getseltext);
ShowMessage(intToStr(StartItemNo)+' * '+intToStr(StartItemOffs)+' * '+intToStr(EndItemNo)+' * '+intToStr(EndItemOffs)+#13#10+
intToStr(memoPos)+' * '+intToStr(memoPos+laenge));
I have problems with memo.GetSelectionBounds(StartItemNo, ...) and RVGetLinearCaretPos(memo)
If I stand at the beginning of a marked text I want to set caret at the end of the marked text.
3 * 6 * 4 * 18 // GetSelectionBounds
95 * 112 // memoPos * memoPos+laenge
Background:
I mark a text. Then I change font.color to blue and I underline the marked text by clicking a button (or F11).
if I mark the text from left to right I stand at the end of the marked text.
If I press RETURN I change to the next line, BUT the new text has the attributes (blue and underlined) of the marked text.
This I can change:
//look some lines below //<<<<-------------------------------
cd.color:= 0; Memo.ApplyStyleConversion(rv_COLOR);
Memo.ApplyStyleConversion(rv_CLEARUNDERLINE);
if query1.state in [dsEdit, dsInsert] then query1.Post;
But if caret stands at the beginning of marked text I first have to set caret at the end of the marked text. Therfore I must know if I stand at the beginning or end of the marked text
...
memo.GetSelectionBounds(StartItemNo, StartItemOffs, EndItemNo, EndItemOffs, true);
memoPos:=RVGetLinearCaretPos(memo); laenge:= length(memo.getseltext); memo.deselect;
//ShowMessage(intToStr(StartItemNo)+' * '+intToStr(StartItemOffs)+' * '+intToStr(EndItemNo)+' * '+intToStr(EndItemOffs)+#13#10+
// intToStr(memoPos)+' * '+intToStr(memoPos+laenge));
//if caret stands at the beginning then
RVSetLinearCaretPos(memo,memoPos+laenge); // <<<<------------------------
cd.color:= 0; Memo.ApplyStyleConversion(rv_COLOR);
Memo.ApplyStyleConversion(rv_CLEARUNDERLINE);
if query1.state in [dsEdit, dsInsert] then query1.Post;
thank you for your fast help.
memo.GetSelectionBounds(StartItemNo, StartItemOffs, EndItemNo, EndItemOffs, true);
memoPos:=RVGetLinearCaretPos(memo);
laenge:= length(memo.getseltext);
ShowMessage(intToStr(StartItemNo)+' * '+intToStr(StartItemOffs)+' * '+intToStr(EndItemNo)+' * '+intToStr(EndItemOffs)+#13#10+
intToStr(memoPos)+' * '+intToStr(memoPos+laenge));
I have problems with memo.GetSelectionBounds(StartItemNo, ...) and RVGetLinearCaretPos(memo)
If I stand at the beginning of a marked text I want to set caret at the end of the marked text.
3 * 6 * 4 * 18 // GetSelectionBounds
95 * 112 // memoPos * memoPos+laenge
Background:
I mark a text. Then I change font.color to blue and I underline the marked text by clicking a button (or F11).
if I mark the text from left to right I stand at the end of the marked text.
If I press RETURN I change to the next line, BUT the new text has the attributes (blue and underlined) of the marked text.
This I can change:
//look some lines below //<<<<-------------------------------
cd.color:= 0; Memo.ApplyStyleConversion(rv_COLOR);
Memo.ApplyStyleConversion(rv_CLEARUNDERLINE);
if query1.state in [dsEdit, dsInsert] then query1.Post;
But if caret stands at the beginning of marked text I first have to set caret at the end of the marked text. Therfore I must know if I stand at the beginning or end of the marked text
...
memo.GetSelectionBounds(StartItemNo, StartItemOffs, EndItemNo, EndItemOffs, true);
memoPos:=RVGetLinearCaretPos(memo); laenge:= length(memo.getseltext); memo.deselect;
//ShowMessage(intToStr(StartItemNo)+' * '+intToStr(StartItemOffs)+' * '+intToStr(EndItemNo)+' * '+intToStr(EndItemOffs)+#13#10+
// intToStr(memoPos)+' * '+intToStr(memoPos+laenge));
//if caret stands at the beginning then
RVSetLinearCaretPos(memo,memoPos+laenge); // <<<<------------------------
cd.color:= 0; Memo.ApplyStyleConversion(rv_COLOR);
Memo.ApplyStyleConversion(rv_CLEARUNDERLINE);
if query1.state in [dsEdit, dsInsert] then query1.Post;
Last edited by j&b on Sun Sep 28, 2008 10:08 am, edited 1 time in total.
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
If you call GetSelectionBounds with the last parameter = True, the selection will be returned in "normalized form", i.e. as if the caret is at the end of selection.
This code moves the caret to the end of selection:
This code moves the caret to the end of selection:
Code: Select all
memo.TopLevelEditor.GetSelectionBounds(StartItemNo, StartItemOffs, EndItemNo, EndItemOffs, true);
if StartItemNo>=0 then // selection exists
memo.TopLevelEditor.SetSelectionBounds(StartItemNo, StartItemOffs, EndItemNo, EndItemOffs);
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Selection may include several items. In this case OffsetInCurItem may be small and laenge may be large, regardless of the caret position.
If you want to use functions from RVLinear.pas, you can use RVGetSelection. If the caret is before the selection, SelLength is negative:
Note that GetSelectionBounds and SetSelectionBounds work faster than RVGetSelection and RVSetSelection.
If you want to use functions from RVLinear.pas, you can use RVGetSelection. If the caret is before the selection, SelLength is negative:
Code: Select all
var SelStart, SelLength: Integer;
begin
RVGetSelection(RichViewEdit1, SelStart, SelLength);
if SelLength<0 then
RVSetSelection(RichViewEdit1, SelStart+SelLength, -SelLength);
end;