The title says it all, whenever I type text into my TextField and wait 1 second for the parser (thank you, @player_03 btw) to highlight as required, it removes the whitespaces and I am unsure how to stop either the parser or my code from doing that.
Here is my code:
import openfl.text.Font;
import openfl.display.Sprite;
import openfl.text.TextField;
import openfl.text.TextFormat;
import openfl.Assets;
import openfl.events.Event;
import openfl.events.TextEvent;
import player03.markdownparser.MarkdownParser;
import player03.markdownparser.MarkdownTag;
import openfl.text.TextFieldType;
import openfl.utils.Timer;
import openfl.events.TimerEvent;
class CodeEditor extends Sprite
{
private var _mainText:TextField;
private var _lineNumbersText:TextField;
private var _sourceCode:Font;
private var _time:Timer;
public function new()
{
super();
_sourceCode = Assets.getFont("font/sourceCode.ttf");
_mainText = new TextField();
_mainText.defaultTextFormat = new TextFormat(_sourceCode.fontName, 11, 0x000000);
_mainText.x = x;
_mainText.y = y + 20;
_mainText.selectable = true;
_mainText.embedFonts = true;
_mainText.wordWrap = true;
_mainText.multiline = true;
_mainText.type = TextFieldType.INPUT;
_mainText.height = 350;
_mainText.width = 500;
_mainText.text = "Some text.";
_time = new Timer(1000, 1);
_time.addEventListener(TimerEvent.TIMER_COMPLETE, textChangeDelayed);
graphics.beginFill(0xDDDDDD, 1);
graphics.drawRect(x, y, 500, 300);
addEventListener(Event.ADDED_TO_STAGE, init);
_mainText.addEventListener(TextEvent.TEXT_INPUT, input);
}
private function init(e:Event):Void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
addChild(_mainText);
}
private function input(e:TextEvent):Void
{
if (_time.running)
_time.stop();
_time.start();
}
private function parseAll(parser:MarkdownParser):Void
{
parser.parse(_mainText.text).apply(_mainText);
}
private function textChangeDelayed(e:TimerEvent):Void
{
var parser:MarkdownParser = new MarkdownParser(
[
new MarkdownTag("Common Keywords",
"(super|private|public|inline|var|class|new|function|extends|implements|static|if|else|try|catch|switch|case|break|continue|for|while) ",
new TextFormat(_sourceCode.fontName, 11, 0x0000FF))
]
);
parseAll(parser);
_time.reset();
}
}
Here is the result before the parse:
and after:
I can’t think of why it would do that in the first place, maybe it is something to do with how the parser matches patterns, so it may require tweaking maybe? The parser, by the way, can be found here.
Thank you for any help in solving this matter.