From ce8f9b695cc524ee4678216912b6c899ca9976b7 Mon Sep 17 00:00:00 2001
From: "Cheng-Han, Wu" <jackymaxj@gmail.com>
Date: Mon, 1 Feb 2016 00:42:30 -0600
Subject: [PATCH] Fixed isInCode and code block textcomplete might not correct

---
 public/js/index.js | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/public/js/index.js b/public/js/index.js
index f4b6904..6a152a1 100644
--- a/public/js/index.js
+++ b/public/js/index.js
@@ -2191,7 +2191,7 @@ function checkCursorMenu() {
 var isInCode = false;
 
 function checkInCode() {
-    isInCode = checkAbove() && checkBelow();
+    isInCode = checkAbove();
 }
 
 function checkAbove() {
@@ -2208,9 +2208,9 @@ function checkBelow() {
     var cursor = editor.getCursor();
     var count = editor.lineCount();
     var text = [];
-    for (var i = cursor.line + 1; i < count; i++) //not contain current line
+    for (var i = cursor.line + 1; i < count; i++) //contain current line
         text.push(editor.getLine(i));
-    text = text.join('\n') + '\n' + editor.getLine(cursor.line).slice(0, cursor.ch);
+    text = editor.getLine(cursor.line).slice(cursor.ch) + '\n' + text.join('\n');
     //console.log(text);
     return matchInCode(text);
 }
@@ -2279,7 +2279,7 @@ $(editor.getInputField())
             },
             replace: function (lang) {
                 var ending = '';
-                if (isInCode) {
+                if (!checkBelow()) {
                     ending = '\n\n```';
                 }
                 if (this.langs.indexOf(lang) !== -1)
@@ -2299,7 +2299,7 @@ $(editor.getInputField())
             },
             context: function (text) {
                 checkCursorMenu();
-                return true;
+                return isInCode;
             }
     },
         { //header