From 79705e9b1404b848cd11bc2801270633e2ee657a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=96=9F=E9=85=8C=20=E9=B5=AC=E5=85=84?= <tgckpg@gmail.com>
Date: Thu, 31 Mar 2016 03:12:18 +0800
Subject: [PATCH] Reset analyzed content when needed

---
 botanjs/src/Components/Vim/Cursor.js              | 15 ++++++++++-----
 botanjs/src/Components/Vim/Syntax/Analyzer.js     |  5 +++++
 .../src/externs/Components.Vim.Syntax.Analyzer.js |  2 ++
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/botanjs/src/Components/Vim/Cursor.js b/botanjs/src/Components/Vim/Cursor.js
index 47b10ad7..ce66bd86 100644
--- a/botanjs/src/Components/Vim/Cursor.js
+++ b/botanjs/src/Components/Vim/Cursor.js
@@ -191,10 +191,10 @@
 		this.PEnd = P + 1;
 		this.__p = P;
 
-		this.__fireUpdate();
+		this.__visualUpdate();
 	};
 
-	Cursor.prototype.__fireUpdate = function()
+	Cursor.prototype.__visualUpdate = function()
 	{
 		if( 0 < this.__suppEvt )
 		{
@@ -313,7 +313,7 @@
 		this.action = new (Actions[ name ])( this );
 		this.__pulseMsg = null;
 
-		this.__fireUpdate();
+		this.__visualUpdate();
 	};
 
 	Cursor.prototype.closeAction = function()
@@ -323,7 +323,10 @@
 		this.__pulseMsg = this.action.getMessage();
 		this.action = null;
 
-		this.__fireUpdate();
+		// Reset the analyzed content
+		this.Vim.contentAnalyzer.reset();
+
+		this.__visualUpdate();
 	};
 
 	// Open, Run, then close an action
@@ -335,7 +338,9 @@
 		this.__pulseMsg = action.getMessage();
 		action.dispose();
 
-		this.__fireUpdate();
+		this.Vim.contentAnalyzer.reset();
+
+		this.__visualUpdate();
 	};
 
 	Cursor.prototype.suppressEvent = function() { ++ this.__suppEvt; };
diff --git a/botanjs/src/Components/Vim/Syntax/Analyzer.js b/botanjs/src/Components/Vim/Syntax/Analyzer.js
index 131ec754..54014ce9 100644
--- a/botanjs/src/Components/Vim/Syntax/Analyzer.js
+++ b/botanjs/src/Components/Vim/Syntax/Analyzer.js
@@ -277,6 +277,11 @@
 		return pairs;
 	};
 
+	Analyzer.prototype.reset = function()
+	{
+		this.__tokpairs = {};
+	};
+
 	Analyzer.prototype.quoteAt = function( p )
 	{
 		var c = this.__feeder.content;
diff --git a/botanjs/src/externs/Components.Vim.Syntax.Analyzer.js b/botanjs/src/externs/Components.Vim.Syntax.Analyzer.js
index 47a3b3b5..24f603cc 100644
--- a/botanjs/src/externs/Components.Vim.Syntax.Analyzer.js
+++ b/botanjs/src/externs/Components.Vim.Syntax.Analyzer.js
@@ -9,3 +9,5 @@ Components.Vim.Syntax.Analyzer.bracketIn;
 Components.Vim.Syntax.Analyzer.wordAt;
 /** @type Function */
 Components.Vim.Syntax.Analyzer.quoteAt;
+/** @type Function */
+Components.Vim.Syntax.Analyzer.reset;