You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2015/09/11 21:34:17 UTC

[5/6] allura git commit: WIP: minor tweaking

WIP: minor tweaking


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/8245c224
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/8245c224
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/8245c224

Branch: refs/heads/db/7955
Commit: 8245c224cd9725b612a340beae2bb0d0921ba977
Parents: 22ed50f
Author: Dave Brondsema <db...@slashdotmedia.com>
Authored: Thu Sep 10 22:03:47 2015 +0000
Committer: Dave Brondsema <db...@slashdotmedia.com>
Committed: Thu Sep 10 22:03:47 2015 +0000

----------------------------------------------------------------------
 .../lib/widgets/resources/js/sf_markitup.js     | 36 +++++++++++++++-----
 1 file changed, 28 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/8245c224/Allura/allura/lib/widgets/resources/js/sf_markitup.js
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/widgets/resources/js/sf_markitup.js b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
index 8aeb551..0c75f09 100644
--- a/Allura/allura/lib/widgets/resources/js/sf_markitup.js
+++ b/Allura/allura/lib/widgets/resources/js/sf_markitup.js
@@ -106,7 +106,7 @@ $(window).load(function() {
                 if (typeof line !== 'object') {
                   throw 'fencing_line() takes a "line" object (not a line number, or line text).  Got: ' + typeof line + ': ' + line;
                 }
-                return line.styles && line.styles.length > 2 && line.styles[2].indexOf('formatting-code-block') !== -1;
+                return line.styles && line.styles[2] && line.styles[2].indexOf('formatting-code-block') !== -1;
               }
 
               function code_type(cm, line_num, line, firstTok, lastTok) {
@@ -137,15 +137,36 @@ $(window).load(function() {
               var cm = editor.codemirror,
                 cur_start = cm.getCursor('start'),
                 cur_end = cm.getCursor('end'),
-                tok = cm.getTokenAt(cur_start),
-                types = tok.type ? tok.type.split(' ') : [],
+                tok = cm.getTokenAt({line: cur_start.line, ch: cur_start.ch || 1}), // avoid ch 0 which is a cursor pos but not token
                 line = cm.getLineHandle(cur_start.line),
-                lastTok = !!line.text && cm.getTokenAt({line: cur_start.line, ch: line.text.length-1}),
-                is_code = code_type(cm, cur_start.line, line, tok, lastTok);
+                is_code = code_type(cm, cur_start.line, line, tok);
               var block_start, block_end, lineCount;
 
-              console.log(line);
+              console.log('cur:', cur_start, cur_end);
               console.log('code:', is_code);
+              /*
+              DEBUG
+              */
+              for (var i = 0; i < cm.lineCount(); i++) {
+                tok0 = cm.getTokenAt({line: i, ch: 0});
+                tok1 = cm.getTokenAt({line: i, ch: 1});
+                //types0 = cm.getTokenTypeAt({line: i, ch:0});
+                //types1 = cm.getTokenTypeAt({line: i, ch:1});
+                lineX = cm.getLineHandle(i);
+                //lineToks = cm.getLineTokens(i);
+                //lastTok = lineToks.length && lineToks[lineToks.length-1]
+                lastTokkk = lineX.text && cm.getTokenAt({line: i, ch: lineX.text.length-1});
+                console.log('line', i,
+                  tok0.type, ',', tok1.type, ',',
+                  //tok0.state.base.indentedCode, tok1.state.base.indentedCode,
+                  'last tok indented:', lastTokkk && lastTokkk.state.base.indentedCode,
+                  'first tok indented:', tok1.state.base.indentedCode,
+                  'last tok inline code:', lastTokkk && lastTokkk.state.base.code,
+                  'first tok inline code:', tok1.state.base.code,
+                  'last tok type:', lastTokkk && lastTokkk.type,
+                  'styles:', lineX && lineX.styles, lineX && lineX.text);
+                //console.log(cm.getLineTokens(i));
+              }
 
               if (is_code === 'single') {
                 // similar to some SimpleMDE _toggleBlock logic
@@ -168,7 +189,6 @@ $(window).load(function() {
                 // no selection, search for ends of this fenced block
 
                 var search_from = cur_start.line;
-                console.log('fencing?', fencing_line(cm.getLineHandle(cur_start.line)), cur_start.line);
                 if (fencing_line(cm.getLineHandle(cur_start.line))) {  // gets a little tricky if cursor is right on a fenced line
                   console.log(code_type(cm, cur_start.line+1));
                   if (code_type(cm, cur_start.line+1) === 'fenced') {
@@ -257,7 +277,7 @@ $(window).load(function() {
                   var start_line_sel = cur_start.line + 1,
                     end_line_sel = cur_end.line + 1,
                     repl_start = '~~~~\n',
-                    repl_end = '\n~~~~';
+                    repl_end = '\n~~~~\n';
                   // ensure a blank prev line
                   if (cm.getLine(cur_start.line-1)) {
                     repl_start = '\n' + repl_start;