jacobslusser / ScintillaNET

A Windows Forms control, wrapper, and bindings for the Scintilla text editor.
MIT License
967 stars 242 forks source link

Some help creating a CTRL+Click thing. #229

Closed Ahmad45123 closed 8 years ago

Ahmad45123 commented 8 years ago

I am trying to make something like CTRL+Click to navigate to functions declaration just like VS.

I have done this:

 Private Sub Editor_KeyDown(sender As Object, e As KeyEventArgs) Handles Editor.KeyDown
        If e.KeyCode = Keys.ControlKey Then
            'The pos.
            Dim pos = Editor.CharPositionFromPointClose(Editor.PointToClient(MousePosition).X, Editor.PointToClient(MousePosition).Y)

            'Get what is there.
            Dim item As String = Editor.GetWordFromPosition(pos)

            'Loop in defines for it.
            If CodeParts.Defines.FindAll(Function(x) x.DefineName = item).Count > 0 Then
                Editor.StartStyling(Editor.WordStartPosition(pos, true))
                Editor.SetStyling(Editor.WordEndPosition(pos, true) - Editor.WordStartPosition(pos, true), Styles.Hotspot)
            End If
        End If
    End Sub

However, The hotspot styling doesn't appear.. I think its just because that place is already styled.. So, if thats correct, How to clear the style from only a specific region of code ?

After that, I want to clear the hotspot styling when the mouse go away from it.. Sooo, Any idea how I can do this ? :/

jacobslusser commented 8 years ago

I'm a little unclear on what you mean by "clear the style from only a specific region of code"... but take a look at the HotspotClick and HotspotReleaseClick events to see if that helps.

Ahmad45123 commented 8 years ago

Ik that, I want to remove the hotspot styling when the mouse moves away.. but I can't find something like RemoveStyling or ``

Ahmad45123 commented 8 years ago

Oops

jacobslusser commented 8 years ago

Could you be looking for Scintilla.Colorize?

Ahmad45123 commented 8 years ago

No lol, Is it really that complex ? xD I just did it without any on runtime colorzing and without the hotspots xD But if I got it working right, I will defo add it. https://github.com/JohnyMac/ExtremeStudio/blob/e81095abe5268241bae263d950aae89e17cc5dfb/ExtremeStudio/DockPanel%20Forms/MainForm%20Docks/EditorDock/EditorDock.vb#L746-L859

Look, How do I make hotspots ? I just make a custom styling with .Hotspot set to true, right ? It doesn't work :/

jacobslusser commented 8 years ago

Sorry dude... I guess I didn't understand the question...

You would use hotspots like this. Assume I'm using the VB lexer and I want all comments to be clickable hotspots, I would set up my styles like this (in addition to what is normally needed to set up lexers and styles):

scintilla.Styles[Style.Vb.Comment].Hotspot = true;

Then handle one of the hotspot click events such as this:

private void scintilla_HotspotReleaseClick(object sender, HotspotClickEventArgs e)
{
    var startPos = scintilla.WordStartPosition(e.Position, true);
    var endPos = scintilla.WordEndPosition(e.Position, true);
    var text = scintilla.GetTextRange(startPos, endPos - startPos);
    if (!string.IsNullOrEmpty(text))
    {
        MessageBox.Show(text);
    }
}
Ahmad45123 commented 8 years ago

Okay, that worked, I got an idea for it, Thanks.