public void Execute(ScNotification notification)
        {
            if (notification.Header.Code != (ulong) SciMsg.SCN_UPDATEUI)
                return;
            if (notification.Updated != (int) SciMsg.SC_UPDATE_SELECTION)
                return;

            var scintillaGateway = gatewayFactory();
            var selectionLength = scintillaGateway.GetSelectionLength();

            if (selectionLength != GuidHelperConstants.StartPartOfGuidLength
                && selectionLength != GuidHelperConstants.EndPartOfGuidLength)
                return;

            var anchor = scintillaGateway.GetAnchor();
            var currentPos = scintillaGateway.GetCurrentPos();
            var absolutePosStart = Position.Min(anchor, currentPos);
            var lineNumber = scintillaGateway.LineFromPosition(absolutePosStart);
            var lineContent = scintillaGateway.GetLine(lineNumber);

            var absolutePosOfLine = scintillaGateway.PositionFromLine(lineNumber);
            var relativeLineOfset = (absolutePosStart - absolutePosOfLine).Value;

            var isLeftToRigthSelection = currentPos > anchor;

            switch (selectionLength)
            {
                case GuidHelperConstants.StartPartOfGuidLength:
                {
                    var isMatch = (lineContent.Length >= GuidHelperConstants.Regexlength + relativeLineOfset && GuidHelperConstants.GuidRex.IsMatch(lineContent, relativeLineOfset));
                    if (!isMatch)
                        return;

                    var end = new Position(absolutePosOfLine.Value + relativeLineOfset + GuidHelperConstants.Regexlength);
                    if (isLeftToRigthSelection)
                    {
                        scintillaGateway.SetAnchor(absolutePosStart);
                        scintillaGateway.SetCurrentPos(end);
                    }
                    else // "reverse" selection from right-to-left
                    {
                        scintillaGateway.SetAnchor(end);
                        scintillaGateway.SetCurrentPos(absolutePosStart);
                    }
                }
                    break;

                case GuidHelperConstants.EndPartOfGuidLength:
                {
                    var isMatch = relativeLineOfset >= LengthGuidExceptLastPart
                        && lineContent.Length >= GuidHelperConstants.Regexlength
                        && GuidHelperConstants.GuidRex.IsMatch(lineContent, relativeLineOfset - LengthGuidExceptLastPart);
                    if (!isMatch)
                        return;

                    var finalStartSelection = new Position(absolutePosStart.Value - LengthGuidExceptLastPart);
                    var end = new Position(finalStartSelection.Value + GuidHelperConstants.Regexlength);

                    if (isLeftToRigthSelection)
                    {
                        scintillaGateway.SetAnchor(finalStartSelection);
                        scintillaGateway.SetCurrentPos(end);
                    }
                    else // "reverse" selection from right-to-left
                    {
                        scintillaGateway.SetAnchor(end);
                        scintillaGateway.SetCurrentPos(finalStartSelection);
                    }
                }
                    break;
            }
        }
        public static void OnNotification(ScNotification notification)
        {
            if (notification.Header.Code == (uint)NppMsg.NPPN_FILESAVED)
            {
                OnFileChanged();
                return;
            }
            else if (notification.Header.Code == (uint)SciMsg.SCN_MODIFIED && (notification.ModificationType & (int)SciMsg.SC_MOD_INSERTTEXT) == (int)SciMsg.SC_MOD_INSERTTEXT)
            {
                OnFileOpened();
                return;
            }

            var handler = _onNotified;
            if (handler != null)
                handler.Invoke(null, notification);
        }
Example #3
0
 public static void OnNotification(ScNotification notification)
 {
     selectWholeGuidIfStartOrEndIsSelected.Execute(notification);
 }