Fix e.toggleComment being undefined in CM sublime keymap (#4662)

* Create comment.js

* Update tiddlywiki.files
optimising-macrocalls
Simon Huber 2020-06-11 12:45:47 +02:00 zatwierdzone przez GitHub
rodzic e59f606566
commit cbff2fb692
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 11 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,4 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: https://codemirror.net/LICENSE
!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){"use strict";var y={},E=/[^\s\u00a0]/,M=e.Pos;function s(e){var n=e.search(E);return-1==n?0:n}function S(e,n){var t=e.getMode();return!1!==t.useInnerComments&&t.innerMode?e.getModeAt(n):t}e.commands.toggleComment=function(e){e.toggleComment()},e.defineExtension("toggleComment",function(e){e=e||y;for(var n=this,t=1/0,i=this.listSelections(),l=null,o=i.length-1;0<=o;o--){var r=i[o].from(),m=i[o].to();r.line>=t||(m.line>=t&&(m=M(t,0)),t=r.line,null==l?l=n.uncomment(r,m,e)?"un":(n.lineComment(r,m,e),"line"):"un"==l?n.uncomment(r,m,e):n.lineComment(r,m,e))}}),e.defineExtension("lineComment",function(o,e,r){r=r||y;var n,t,m,a,c,g,f=this,i=S(f,o),l=f.getLine(o.line);null!=l&&(n=o,t=l,!/\bstring\b/.test(f.getTokenTypeAt(M(n.line,0)))||/^[\'\"\`]/.test(t))&&((m=r.lineComment||i.lineComment)?(a=Math.min(0!=e.ch||e.line==o.line?e.line+1:e.line,f.lastLine()+1),c=null==r.padding?" ":r.padding,g=r.commentBlankLines||o.line==e.line,f.operation(function(){if(r.indent){for(var e=null,n=o.line;n<a;++n){var t=(i=f.getLine(n)).slice(0,s(i));(null==e||e.length>t.length)&&(e=t)}for(n=o.line;n<a;++n){var i=f.getLine(n),l=e.length;(g||E.test(i))&&(i.slice(0,l)!=e&&(l=s(i)),f.replaceRange(e+m+c,M(n,0),M(n,l)))}}else for(n=o.line;n<a;++n)(g||E.test(f.getLine(n)))&&f.replaceRange(m+c,M(n,0))})):(r.blockCommentStart||i.blockCommentStart)&&(r.fullLines=!0,f.blockComment(o,e,r)))}),e.defineExtension("blockComment",function(i,l,o){o=o||y;var r,m,a=this,c=S(a,i),g=o.blockCommentStart||c.blockCommentStart,f=o.blockCommentEnd||c.blockCommentEnd;g&&f?/\bcomment\b/.test(a.getTokenTypeAt(M(i.line,0)))||((r=Math.min(l.line,a.lastLine()))!=i.line&&0==l.ch&&E.test(a.getLine(r))&&--r,m=null==o.padding?" ":o.padding,i.line>r||a.operation(function(){if(0!=o.fullLines){var e=E.test(a.getLine(r));a.replaceRange(m+f,M(r)),a.replaceRange(g+m,M(i.line,0));var n=o.blockCommentLead||c.blockCommentLead;if(null!=n)for(var t=i.line+1;t<=r;++t)t==r&&!e||a.replaceRange(n+m,M(t,0))}else a.replaceRange(f,l),a.replaceRange(g,i)})):(o.lineComment||c.lineComment)&&0!=o.fullLines&&a.lineComment(i,l,o)}),e.defineExtension("uncomment",function(e,n,t){t=t||y;var l,o=this,i=S(o,e),r=Math.min(0!=n.ch||n.line==e.line?n.line:n.line-1,o.lastLine()),m=Math.min(e.line,r),a=t.lineComment||i.lineComment,c=[],g=null==t.padding?" ":t.padding;e:if(a){for(var f=m;f<=r;++f){var s=o.getLine(f),d=s.indexOf(a);if(-1<d&&!/comment/.test(o.getTokenTypeAt(M(f,d+1)))&&(d=-1),-1==d&&E.test(s))break e;if(-1<d&&E.test(s.slice(0,d)))break e;c.push(s)}if(o.operation(function(){for(var e=m;e<=r;++e){var n=c[e-m],t=n.indexOf(a),i=t+a.length;t<0||(n.slice(i,i+g.length)==g&&(i+=g.length),l=!0,o.replaceRange("",M(e,t),M(e,i)))}}),l)return!0}var u=t.blockCommentStart||i.blockCommentStart,h=t.blockCommentEnd||i.blockCommentEnd;if(!u||!h)return!1;var p=t.blockCommentLead||i.blockCommentLead,C=o.getLine(m),b=C.indexOf(u);if(-1==b)return!1;var v=r==m?C:o.getLine(r),k=v.indexOf(h,r==m?b+u.length:0),L=M(m,b+1),x=M(r,k+1);if(-1==k||!/comment/.test(o.getTokenTypeAt(L))||!/comment/.test(o.getTokenTypeAt(x))||-1<o.getRange(L,x,"\n").indexOf(h))return!1;var R=-1==(T=C.lastIndexOf(u,e.ch))?-1:C.slice(0,e.ch).indexOf(h,T+u.length);if(-1!=T&&-1!=R&&R+h.length!=e.ch)return!1;R=v.indexOf(h,n.ch);var O=v.slice(n.ch).lastIndexOf(u,R-n.ch),T=-1==R||-1==O?-1:n.ch+O;return(-1==R||-1==T||T==n.ch)&&(o.operation(function(){o.replaceRange("",M(r,k-(g&&v.slice(k-g.length,k)==g?g.length:0)),M(r,k+h.length));var e=b+u.length;if(g&&C.slice(e,e+g.length)==g&&(e+=g.length),o.replaceRange("",M(m,b),M(m,e)),p)for(var n=m+1;n<=r;++n){var t,i=o.getLine(n),l=i.indexOf(p);-1==l||E.test(i.slice(0,l))||(t=l+p.length,g&&i.slice(t,t+g.length)==g&&(t+=g.length),o.replaceRange("",M(n,l),M(n,t)))}}),!0)})});

Wyświetl plik

@ -7,6 +7,13 @@
"title": "$:/plugins/tiddlywiki/codemirror/keymap/sublime.js",
"module-type": "codemirror"
}
},{
"file": "addons/comment/comment.js",
"fields": {
"type": "application/javascript",
"title": "$:/plugins/tiddlywiki/codemirror/addons/comment/comment.js",
"module-type": "codemirror"
}
}
]
}