Re: Do I need to call SetSel?

Mitchell <[email protected]> Mon, 20 Jan 2025 10:16:01 -0500
Newsgroups gmane.comp.lib.scintilla.devel
Message-ID <[email protected]>
Hi,

> On Jan 20, 2025, at 5:28 AM, Andrew Truckle <[email protected]> wrote:
> 
> I am using OnAutoCCompleted to detect that the user has selected <!-- from the drop list. Then, I add the trailing --> and  adjust the caret position:
> 
> if (strSelectedText == L"!--") {
> // Get the current caret position
> const auto currentPos = m_edit.GetCurrentPos();
> 
> // Insert the closing part -->
> m_edit.InsertText(currentPos, L"-->");
> 
> // Move the caret between <!-- and -->
> m_edit.SetCurrentPos(currentPos);
> m_edit.SetSel(currentPos, currentPos); // Clear selection to place caret
> }
> 
> Is it obligatory that I need to call SetSel?

Since you called `SetCurrentPos()`, which just sets the caret (not the anchor), that will create a selection (intentional or not). The call to `SetSel()` corrects this, so it is obligatory for your case.

You could replace the two calls with a single call to `SetEmptySelection(currentPos)` which ought to have the same effect.

Cheers,
Mitchell

-- 
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/scintilla-interest/C37DF8C0-74F8-45D9-B8EB-740CB99D1799%40foicica.com.