Quantcast
Channel: ScintillaNET Forum Rss Feed
Viewing all 296 articles
Browse latest View live

New Post: Custom Lexer Unicode

$
0
0
It should already account for Unicode characters, a char is 2-bytes in .net, and strings are already in Unicode. Are you sure you don't have a block of 2 bytes that are both NUL ('\0')? If you need to have NUL characters as a valid piece of a string (I don't know of any programming languages that this is allowed in) then use a different character as the escape character, or else re-write the ConsumeString function so that it doesn't account for any form of escape sequence. Also, are you sure that you have loaded the string your working with as unicode in the first place, because if it was loaded as utf8 or ascii, that would cause problems.

New Post: Custom Lexer Unicode

$
0
0
I'm Loading a text file with stream reader which has special characters...
It's a Custom Script called Dragon speak for a MMORPG called Furcadia. The Game supports some Unicode characters

I'm a novice at Programming and I'm not sure exactly whats Happening but I'm trying to build a custom Editor for the script
(0:50) when countdown timer 57 goes off
* (1:200) and variable %ANIMATIONS is equal to 1
  (1:200) and variable %POWER_TAC is equal to 1
  (1:200) and variable %CONTACT is equal to 1
  (1:201) and variable %CONTACT_RND is greater than 10
       (5:312) set variable %CONTACT_BRG to the total of rolling 1 dice with 359 sides plus 1
       (5:312) set variable %CONTACT_BRG.y to the total of rolling 1 dice with 359 sides plus 1
       (5:312) set variable %CONTACT_SIZE to the total of rolling 1 dice with 100 sides plus 0
       (5:312) set variable %CONTACT_HZ to the total of rolling 1 dice with 100 sides plus 0
       (5:312) set variable %CONTACT_SPD to the total of rolling 1 dice with 9 sides plus 0
       (5:300) set variable %CONTACT to 2
* Position E-Mits
    (3:2) at position (%COMMAND_FUNCTIONS) on the map,
       (5:201) emit message {SENSORS: CONTACT Bearing %CONTACT_BRG ° mark %CONTACT_BRG.y ° } to any furre present
    (3:3) within the diamond (%Tact_Cord) - (%Tact_Cord2)
       (5:201) emit message {SENSORS: CONTACT Bearing %CONTACT_BRG ° mark %CONTACT_BRG.y ° } to any furre present
*  (3:3) within the diamond (%Ops_Cord) - (%Ops_Cord2)
*    (5:201) emit message {SENSORS: CONTACT Bearing %CONTACT_BRG ° mark %CONTACT_BRG.y ° } to any furre present
       (5:300) set variable %CLASS to 0
       (5:300) set variable %SIZE to 0
       (5:300) set variable %HZ to 0
       (5:300) set variable %CSPEED to 0
the {} strings break on the degree sign... Like it Shifts the Highlighting over

New Post: Custom Lexer Unicode

$
0
0
The degree sign there is actually in UTF-8, but everything I'm looking at says it should work..... If it's shifting the highlighting over then it means that a character isn't getting properly Consume()'d somewhere in the string..... Modify the ConsumeString method and check if the current character is larger than 0x7F, if it is, add 1 to the number of characters being consumed. That should (hopefully) detect the UTF-8 character and consume both bytes of it.

New Post: Custom Lexer Unicode

$
0
0
Adding this Code helped the Shifting But now just on the one Line Characters After the Degree sing show up as default

Side Note: I added a dragonspeak.xml file and set my customlexer to dragonspeak.. But everything there appears as default Hightlighting
            else if ((char)CurrentCharacter > 0x7F)
            {
                Consume();
            }

New Post: Custom Lexer Unicode

$
0
0
New problem with Highlight Alignment
I'm attempting to highlight 0-9#- Characters But One Char before the hightleted character is highlighted

"DSPK V4.00" The V is Hhisglighted and the dor is highlighted but the last 0 is not.. Any Idea whats happening?
using System;
using System.Drawing;
using System.Collections.Generic;

namespace ScintillaNET.Lexers
{
    public sealed class dsLexer : CustomLexer
    {
        public override string LexerName { get { return "dragonspeak"; } }
        
        private const int STYLE_STRING = 11;
        private const int STYLE_NUMBER = 12;
        private const int STYLE_COMMENT = 14;
        private const int STYLE_NUM_VAR = 15;
        private const int STYLE_STR_VAR = 16;
        private const int STYLE_HEADER = 17;

        public dsLexer(Scintilla scintilla) : base(scintilla) { }

        private enum State : int
        {
            Unknown = STATE_UNKNOWN,
            String,
            Comment,
            Number,
            StringVar,
            NumVar,
            Header
        }

        new private State CurrentState
        {
            get { return (State)base.CurrentState; }
            set { base.CurrentState = (int)value; }
        }

        public override Dictionary<string, int> StyleNameMapping
        {
            get
            {
                return new Dictionary<string, int>()
                {
                    { "Comment", STYLE_COMMENT },
                    { "Number", STYLE_NUMBER },
                    { "String", STYLE_STRING },
                    { "StringVariable", STYLE_STR_VAR},
                    { "NumberVariable", STYLE_NUM_VAR},
                    { "Header", STYLE_HEADER}
                };
            }
        }
        public override Dictionary<string, int> KeywordNameMapping
        {
            get
            {
                return new Dictionary<string, int>();
            }
        }
     
        protected override void Initialize()
        {

            base.Initialize();
        }

        protected override void InitializeStateFromStyle(int style)
        {
            switch (style)
            {
                case STYLE_STRING:
                    CurrentState = State.String;
                    break;
                // Otherwise we don't need to carry the
                // state on from the previous line.
                case STYLE_HEADER:
                    CurrentState = State.Header;
                    break;
                case STYLE_NUM_VAR:
                    CurrentState = State.NumVar;
                    break;
                default:
                    break;
            }
        }

        protected override void Style()
        {
            StartStyling();

            while (!EndOfText)
            {
                switch (CurrentState)
                {
                    case State.Unknown:
                        bool consumed = false;
                        switch (CurrentCharacter)
                        {
                            case '0':
                            case '1':
                            case '2':
                            case '3':
                            case '4':
                            case '5':
                            case '6':
                            case '7':
                            case '8':
                            case '9':
                            case '#':
                            case '-':
                                 CurrentState = State.Number;
                                 break;
                            case '{':
                                CurrentState = State.String;
                                break;
                            case '*':
                                CurrentState = State.Comment;

                                break;
                            case '%':
                                CurrentState = State.NumVar;
                                //Consume();
                                //SetStyle(STYLE_NUM_VAR);
                                //consumed = true;
                                break;
                            case '~':
                                CurrentState = State.StringVar;
                                //Consume();
                                //SetStyle(STYLE_STR_VAR);
                                //consumed = true;
                                break;
                            default:
                                if (IsWhitespace(CurrentCharacter))
                                {
                                    ConsumeWhitespace();
                                    consumed = true;
                                }
                                else
                                {
                                    SetStyle(STYLE_DEFAULT);
                                }
                                break;
                        }
                        if (!consumed)
                            Consume();
                        break;
                    case State.Comment:
                        ConsumeUntilEOL(STYLE_COMMENT);
                        CurrentState = State.Unknown;
                        break;
                    case State.String:
                        // We're using '\0' as the escape character because a NUL character
                        // doesn't usually appear in text-based documents.
                        ConsumeString(STYLE_STRING, '\0',false, false, '}');
                        consumed = true;
                        CurrentState = State.Unknown;
                        break;
                    case State.NumVar:
                        if (!IsIdentifier(CurrentCharacter))
                        {
                            CurrentState = State.Unknown;
                            Consume();
                            SetStyle(STYLE_DEFAULT);
                        }
                        else
                        {
                            Consume();
                            SetStyle(STYLE_NUM_VAR); 
                            
                        }

              
                        break;
                    case State.StringVar:
                        if (!IsIdentifier(CurrentCharacter))
                        {
                            CurrentState = State.Unknown;
                            SetStyle(STYLE_DEFAULT);
                        }
                        else
                        {
                            SetStyle(STYLE_STR_VAR);
                            Consume();
                        }
                        
                       
                        break;
                    case State.Number:
                          if (IsNum(CurrentCharacter))
                          {
                             
                            SetStyle(STYLE_NUMBER);
                         Consume(); 
                            }
                          else
                          {
                              CurrentState = State.Unknown;
                             
                              SetStyle(STYLE_DEFAULT);
                                Consume(); 
                          }
                          break;
                    default:
                        throw new Exception("Unknown state!");
                }
            }

            switch (CurrentState)
            {
                case State.Unknown: break;
                case State.Comment:
                    SetStyle(STYLE_COMMENT);
                    break;
                case State.NumVar:
                    SetStyle(STYLE_NUM_VAR);
                    break;
                case State.String:
                    SetStyle(STYLE_STRING);
                    StyleNextLine(); // Continue the style to the next line
                    break;
                case State.Number:
                       SetStyle(STYLE_NUMBER);
                      Consume();
                       break;
                default:
                    throw new Exception("Unknown state!");
            }
        }

     bool IsNum(char c)
        {
            switch (c)
            {
                case '0':
                case '1':
                case '2':
                case '3':
                case '4':
                case '5':
                case '6':
                case '7':
                case '8':
                case '9':
                case '#':
                case '-':
                    return true;
                default:
                    return false;
            }
        }

        
    }
}

New Post: Custom Lexer Unicode

$
0
0
Fixed the problem...
I was loading an ASCII file into the editor with out converting t to UTF8

New Post: ScintillaNET is used in ExHtmlEditor

$
0
0
Hi, thanks you to ScintillaNET.
ScintillaNET is used as text editor in this project (ExHtmlEditor);

ExHtmlEditor is a tool for learning and writing HTML.
The writer will get instant visual rendering output as he type into the text editor.

Thanks again.

New Post: Special AutoComplete

$
0
0
I'm doin a Dynamic Autocomplete list and I'm wondering is it possiple to Match a word or more words in a Phrase

IE
(0:3) This is a Phrase
(0:4) this is phrase two
(0:5) this is Phrase 5

And I want to match the word phrase and have these lines popup

New Post: New Feature: Auto Launch AutoComplete

$
0
0
By default, we have to manually run 'AutoComplete.Show()' in the 'CharAdded' event.

However, I would like to suggest it to be auto-launch.

Default behaviour:
  • If the AutoComplete.List is empty, AutoComplete will not launch.
  • If the AutoComplete.List is not empty, it will launch for matched character enter by user.
  • If the developer want to implement different behaviour, he/she can override the methods or turn it off.
This is the sample codes patch that I can come out with:

This is the original codes of the method of OnCharAdded() in ScintillaNET.Scintilla
///<summary>///     Raises the <see cref="CharAdded"/> event.///</summary>///<param name="e">An <see cref="CharAddedEventArgs"/> that contains the event data.</param>protectedvirtualvoid OnCharAdded(CharAddedEventArgs e)
{
    EventHandler<CharAddedEventArgs> handler = Events[_charAddedEventKey] as EventHandler<CharAddedEventArgs>;
    if (handler != null)
        handler(this, e);

    if (_indentation.SmartIndentType != SmartIndent.None)
        _indentation.CheckSmartIndent(e.Ch);
}
Patches:
private Bool _autoLaunchAutoComplete = true;

public Bool AutoLaunchAutoComplete 
{ 
    get { return _autoLaunchAutoComplete; } 
    set { _autoLaunchAutoComplete = value; } 
}

///<summary>///     Raises the <see cref="CharAdded"/> event.///</summary>///<param name="e">An <see cref="CharAddedEventArgs"/> that contains the event data.</param>protectedvirtualvoid OnCharAdded(CharAddedEventArgs e)
{
    EventHandler<CharAddedEventArgs> handler = Events[_charAddedEventKey] as EventHandler<CharAddedEventArgs>;
    if (handler != null)
        handler(this, e);

    if (_indentation.SmartIndentType != SmartIndent.None)
        _indentation.CheckSmartIndent(e.Ch);

    if (_autoLaunchAutoComplete)
        LaunchAutoComplete();
}

publicvirtualvoid LaunchAutoComplete()
{
    if (this.AutoComplete.List.Count == 0)
        return;

    int pos = this.NativeInterface.GetCurrentPos();
    int length = pos - this.NativeInterface.WordStartPosition(pos, true);
    if (length == 0)
        return;

    this.AutoComplete.Show(length);
}
If the developer don't want automatic launch AutoComplete or he/she want to implement different behaviour, he/she may do this to suspend default behaviour:
ScintillaNET.Scintilla scintilla1 = new ScintillaNET.Scintilla();
scintilla1.AutoLaunchAutoComplete = false;

New Post: Special AutoComplete

$
0
0
Isthis even Doable with ScintillaNet?

New Post: Adding Items to AutoComplete List on Lexer Level?

$
0
0
Hello there,

I'm currently writing a custom Lexer for an Intellisense like dynamic Highlighter. As the logic to achieve this is quite heavy in terms of performance I would like to do the whole dynamic part on Lexer Level.

Highlighting already works, but how can I add new Items to my Autocomplete List on Lexer Level? I tried to #include AutoCompletion.h to the Lexer, but this already gives me various erros, so is this possible at all?

Greetings,
2mQ

New Post: Special AutoComplete

$
0
0
Well, as you do have access to the location of the user's cursor, it should be possible to determine the context from that information.

New Post: Adding Items to AutoComplete List on Lexer Level?

$
0
0
Not from a native lexer, no, it's not possible currently, not as far as I know.

New Post: Adding Items to AutoComplete List on Lexer Level?

$
0
0
Hm ok,
thanks for the reply. Then I will have to parse the text twice.

New Post: Why is TextChanged Event fired multiple times?

$
0
0
Hi again,

I'm still trying to fix this behaviour as I can't achieve this behaviour on Lexer Level and I inserted the proposed code as specified under the link above...

But when I insert the code I just get the error messages from the compiler "ScintillaNET.NativeMethods doesn't contain a definition for SC_MOD_DELETETEXT" (Same for SC_MOD_INSERTTEXT)

So... where can I find those constants?

Greetings,
2mQ

New Post: Only highlight keywords within a certain range

$
0
0
Hi,

does nobody know if thats possible? Can't I force Scintilla when iterating over the text to colour a parsed item seperatly
(an item which is not in the keywords list)? Or can I somehow set int ranges for the keyword lists?

Greetings,
2mQ

New Post: Manually set index of selected AutoComplete Item?

$
0
0
Hi there,

I'm currently trying to give my AutoComplete List a little Memory, just like in Visual Studio. So if I have for example this list:

sin
sinc
sinh

and I choose and accept the second item, "sinc" I want that when the user the next time types a "s", the list automatically selects "sinc" and not "sin", although its above "sinc". So that the list "remembers" the users choices.

I already implemented everything to achieve this, I only have to change the Starting-Selection when the first char is entered and triggers the AutoComplete List. I tried to do so by using

scintilla1.AutoComplete.SelectedIndex = myIndex

but this doesn't work at all. How can I change the selected item then?

Greetings,
2mQ

New Post: Edit Multple lines

$
0
0
Hello there guys, I'm currently building a text editor for my work and I would like to know if there's a simple way to make the editor Edit multiple lines at the same time (Alt + UP or Down). The cursor select these lines but as soon as I type, it goes to the original line. Is there any property I have to set true to edit multiple lines? Sorry if there's is one, I was looking for it, but never found it.

New Post: BUG: scintilla.CurrentPos and scintilla.Caret.Position bugged

$
0
0
Hello,

at the moment I have really hard problems with the Scintilla natives scintilla.CurrentPos and/or scintilla.Caret.Position which both don't work correctly.

If you just display the current position in an extra textbox while typing you will notice that it is heavily bugged and can't be used reliable.

If I type one letter, then a space the position is correct. If I delete that space now with via backspace, the position remains the same although it has changed.

Even worse happens if there are special chars inside the text of the Scintilla Control, like for example 'ü', 'ä' or 'ö' but also 'ß' or '§' (or many more) then the current position gets incremented by two for each of those special chars, although they only count as one!

This also happens when those chars are within comments. As a result it is easily possible (and very likely) that such a simple thing like:
char[] textArray = scintilla1.Text.ToCharArray();
char actualChar = textArray[scintilla1.CurrentPos];
will cause an ArrayOutOfBounds Exception.

Anyone knows how to solve this problem? It is really annoying and makes it basically impossible to use the CurrentPos in a reliable way.

Regards,
2mQ

New Post: BUG: scintilla.CurrentPos and scintilla.Caret.Position bugged

$
0
0
Everything you are describing can easily be explained....

What event are you using to trigger the update of your cursor position text box? You weren't specific... but you would definitely need to be using one. The CurrentPos and/or Caret.Position properties aren't going to notify you of changes, and as a result, the value displayed there could be stale. The NativeScintilla.UpdateUI event is the correct one to be using. It is for this express purpose. The Scintilla documentation describes the event as "Either the text or styling of the document has changed or the selection range or scroll position has changed. Now would be a good time to update any container UI elements that depend on document or view state." Make sure you're using that event to trigger any updates to your position display.

As for the position value being off when you use Unicode characters such as ü', 'ä' or 'ö'... that is because those properties tell you the current byte offset, not the character offset. As you may know Unicode characters can often require more than one byte of storage. This problem is a limitation of the native Scintilla component and has been well documented in these forums. https://www.google.com/#q=Unicode+site%3Ahttp%3A%2F%2Fscintillanet.codeplex.com%2Fdiscussions%2F

Instead, try the NativeScintilla.GetColumn method. It's probably what you're looking for. Per the Scintilla documentation, "returns the column number of a position pos within the document taking the width of tabs into account. This returns the column number of the last tab on the line before pos, plus the number of characters between the last tab and pos. If there are no tab characters on the line, the return value is the number of characters up to the position on the line. In both cases, double byte characters count as a single character." (emphasis on the last line)

If that's not what you're looking for, then try some of the other suggestions in the forums to translate byte offsets to character offsets.

At this point, hopefully the bells are starting to go off and I won't need to explain why your code sample could throw an exception.


Jacob
Viewing all 296 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>