mobileFX WebKitX CEF3 ActiveX 4.x
WebKitXCEF3Lib ActiveX Control / WebKitXCEF3 Object / GetSelection Method

CSS3 Selector of the element to get selection.

If you are unfamiliar with CSS3 Selectors have a look in Finding the correct CSS3 Selector article.

The selection Offset.

The selection Length.

In This Topic
    GetSelection Method
    In This Topic
    Description

    Get selection Offset and Length in HTML buffer.

    Syntax
    Visual Basic
    Public Sub GetSelection( _
       ByVal Selector As String, _
       ByRef Offset As Long, _
       ByRef Length As Long _
    ) 
    Parameters
    Selector

    CSS3 Selector of the element to get selection.

    If you are unfamiliar with CSS3 Selectors have a look in Finding the correct CSS3 Selector article.

    Offset

    The selection Offset.

    Length

    The selection Length.

    Remarks

    This method is used for synchronizing editing between HTML5 Visual Editor of WebKitX ActiveX and a Text Editor in FrontPage and Dreamweaver fashion.

    Example
    Private Sub SelectSource(ByVal Selector As String)
        
        On Error Resume Next
        
        NoDomModifications = True
        
        Dim Offset As Long
        Dim Length As Long
        Dim Sel As New Range
        Dim Pos As Position
        Dim VisibleLinesCount As Long
        Dim TopIndex As Long
        Dim SelLines As Long
        
        CurrentSelector = Selector
        
        WebKitX1.GetSelection Selector, Offset, Length
        
        ' Selection Offset
        Set Pos = Editor.OffsetToPos(Offset)
        Sel.StartLineNo = Pos.LineNo
        Sel.StartColNo = Pos.ColNo
        
        ' Selection Length
        Set Pos = Editor.OffsetToPos(Offset + Length)
        Sel.EndLineNo = Pos.LineNo
        Sel.EndColNo = Pos.ColNo
        
        ' Normalize
        Sel.Normalize
        
        ' Number of selected lines
        SelLines = Sel.EndLineNo - Sel.StartLineNo
        
        ' Number of visible lines
        VisibleLinesCount = Editor.GetVisibleLineCount(0, True)
        
        ' Center selection in editor view
        If SelLines < VisibleLinesCount Then
            
            ' Select!
            Editor.SetSel Sel, False
    
            TopIndex = Sel.StartLineNo - (VisibleLinesCount - SelLines) / 2
            If TopIndex + VisibleLinesCount > Editor.LineCount Then
                TopIndex = Editor.LineCount - VisibleLinesCount
            End If
            If TopIndex < 0 Then TopIndex = 0
            Editor.TopIndex = TopIndex
        
        End If
            
        Editor.SetSel Sel, True
        
        NoDomModifications = False
    
    End Sub
    private void SelectSource(string selector)
    {
        NoDomModifications = true;
        int offset = 0, length = 0, VisibleLinesCount, TopIndex, SelLines;
        Range sel = new Range();
        Position pos = new Position();
        CurrentSelector = selector;
        WebKitXCEF31.GetSelection(selector, ref offset, ref length);
    
        pos = Editor.OffsetToPos(offset);
        sel.StartLineNo = pos.LineNo;
        sel.StartColNo = pos.ColNo;
    
        pos = Editor.OffsetToPos(offset + length);
        sel.EndLineNo = pos.LineNo;
        sel.EndColNo = pos.ColNo;
    
        sel.Normalize();
        SelLines = sel.EndLineNo - sel.StartLineNo;
        VisibleLinesCount = Editor.GetVisibleLineCount(0, true);
        if (SelLines < VisibleLinesCount)
        {
            Editor.SetSel(sel, false);
            TopIndex = sel.StartLineNo - (VisibleLinesCount - SelLines) / 2;
            if (TopIndex + VisibleLinesCount > Editor.LineCount)
            {
                TopIndex = Editor.LineCount - VisibleLinesCount;
            }
            if (TopIndex < 0)
            {
                TopIndex = 0;
            }
            Editor.TopIndex = TopIndex;
        }
        Editor.SetSel(sel, true);
        NoDomModifications = false;
    }
    See Also