Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
wxScintilla 2.01
cgarcia109:
Its related about discovering when there is a selection done or not. From the scintilla documentation its said to use GetSelectionStart()!=GetSelectionEnd(), but this is outdated.
The thing is that empty ranges are kept in the slection range list, and each range has its own anchor and caret.
GetSelectionStart() {
return Platform::Minimum(sel.MainAnchor(), sel.MainCaret());
}
GetSelectionEnd() {
return Platform::Maximum(sel.MainAnchor(), sel.MainCaret());
}
Where MainAnchor and MainCaret refers to the anchor and caret of the MainRange
I think its shown better with an image
Using virtual spaces:
Without virtual spaces(is a rectangular selection):
The last selected "line" is kept as the MainRange of the selection and this is the one used by GetSelectionStart|End calls
Since the last range is empty cbEditor::HasSelection() would return false in both cases, what its not true.
Actually cbEditor as it is now wont copy nothing to clipboard. This is only with rectangular selections.
Ive tried with GetRectangularSelection[Anchor|Caret] but is not perfect.
A vertical empty selection would have diferents anchor caret values returning true.
I think its better just to add a new function/message to wxScintilla
bool IsSelectionEmpty() --> SCI_ISSELECTIONEMPTY --> return sel.Empty()
I dont understand why this message doesnt exits
--- Quote from: jens on September 29, 2009, 09:43:33 pm ---please don't switch multiple select and additional selection typing on as default.
--- End quote ---
Yes they should be selectable, some ppl will like them other not.
eranif:
You should use this to determine whether you got a selection (the below code works for multiple selection as well as for rectangular selections):
--- Code: ---bool wxScintilla::HasSelection() {
return SendMsg (SCI_GETSELTEXT, 0, 0) > 0;
}
--- End code ---
Its the safest and correct way to do it:
http://www.scintilla.org/ScintillaDoc.html#SCI_GETSELTEXT
Eran
Jenna:
What about using:
--- Quote from: http://www.scintilla.org/ScintillaDoc.html#SCI_GETSELECTIONS ---SCI_GETSELECTIONS
Return the number of selections currently active.
--- End quote ---
cgarcia109:
--- Quote from: eranif on September 29, 2009, 10:39:08 pm ---
--- Code: ---bool wxScintilla::HasSelection() {
return SendMsg (SCI_GETSELTEXT, 0, 0) > 0;
}
--- End code ---
--- End quote ---
After some test...
That doesnt works with rectangular selections, cos all ranges receive a final '\n' char. Using virtual spaces if you select some empty space it would return a string like '\n\n\n'
sel.Empty() doesnt work neither cos it checks caret and anchor in real and virtual positions, what doesnt works fine in all cases.
Its needed to check all ranges for real.
You cant trust a single range, most scintilla functionality works over all ranges.
At the end i think this is the better way to check for real selections:
case SCI_ISSELECTIONEMPTY:
for (size_t i=0; i<sel.Count(); i++) {
if(sel.Range(i).anchor.Position() != sel.Range(i).caret.Position())
return false;
}
return true;
or outside scintilla:
cbStyledTextCtrl* control = GetControl();
size_t sels = control->GetSelections();
for (size_t i=0; i<sels ; i++) {
if (control->GetSelectionNCaret(i) != control->GetSelectionNAnchor(i))
return true;
}
return false;
--- Quote from: jens on September 29, 2009, 11:28:09 pm ---SCI_GETSELECTIONS
Return the number of selections currently active.
--- End quote ---
That the first i tried, make more sense, but scintilla always have a selection. The caret alone is an empty selection. That function always return 1+
MortenMacFly:
--- Quote from: jens on September 29, 2009, 09:43:33 pm ---I think the options can be placed on the Margins and caret pane.
I can do that, if it's okay for you.
--- End quote ---
I don't have any plans to switch that on by default. You can do it, if you like. Just please wait until I commit some pending modifications to the scintilla branch to avoid conflicts.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version