foldgutter.css000644 0000001060 14116141676010601 0ustar00000000 000000 .CodeMirror-foldmarker { color: blue; text-shadow: #b9f 1px 1px 2px, #b9f -1px -1px 2px, #b9f 1px -1px 2px, #b9f -1px 1px 2px; font-family: arial; line-height: .3; cursor: pointer; } .CodeMirror-foldgutter { width: .7em; } .CodeMirror-foldgutter-open, .CodeMirror-foldgutter-folded { cursor: pointer; } .CodeMirror-gutters { border-right: 1px solid #fff; background-color: #fff; } .CodeMirror-foldgutter-open:after { content: "\25BE"; } .CodeMirror-foldgutter-folded:after { content: "\25B8"; }folding.js000644 0000011542 14116141702007664 0ustar00000000 000000 exports.default=function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t){var n=this&&this.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(r,l){function i(e){try{d(o.next(e))}catch(e){l(e)}}function f(e){try{d(o.throw(e))}catch(e){l(e)}}function d(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(i,f)}d((o=o.apply(e,t||[])).next())}))};function o(e){e.defineExtension("foldAllByPlugin",(function(){let n=this,o=n.getDoc();n.operation((function(){console.log("fold all by plugin");for(var r=n.lastLine();r>=n.firstLine();--r){let l=n.getLine(r);if("#"==l.charAt(0)&&l.indexOf(" ")>0){let i=n.getLineHandle(r),f=r;try{if("gutterMarkers"in i&&"CodeMirror-foldgutter"in i.gutterMarkers){let r=l.length;l.charAt(l.length-1)!=t&&o.replaceRange(l+t,{line:f,ch:0},{line:f,ch:r+1}),n.foldCode(e.Pos(f,r-1),null,"fold")}}catch(e){console.log("fold all error"),console.log(e)}}}}))})),e.defineExtension("unfoldAllByPlugin",(function(){let n=this,o=n.getDoc();console.log("unfold all by plugin"),n.operation((function(){for(var r=n.lastLine();r>=n.firstLine();--r){let l=n.getLine(r);if("#"==l.charAt(0)&&l.indexOf(" ")>0){let i=n.getLineHandle(r),f=r,d=l.charAt(l.length-1);try{if("gutterMarkers"in i&&"CodeMirror-foldgutter"in i.gutterMarkers){let r=l.length;d==t&&o.replaceRange(l.slice(0,-1),{line:f,ch:0},{line:f,ch:r}),n.foldCode(e.Pos(f,r-1),null,"unfold")}}catch(e){console.log("unfold all error"),console.log(e)}}}}))}));let t=".";function o(n,o,r){console.log("gutter line clicked");let l=n.getDoc(),i=l.getLineHandle(o);l.eachLine((function(t){if(t.text.includes("![")){let r=l.getLineNumber(t)+1;try{let i=l.getLineHandle(r);if(0==i.text.indexOf("#")){t.text,t.text.length;l.replaceRange("\n"+i.text,{line:r,ch:0},{line:r,ch:i.text.length+1}),n.foldCode(e.Pos(o,t.text.length)),n.foldCode(e.Pos(o,t.text.length))}}catch(r){console.log(r);let i=l.lastLine(),f=l.getLineHandle(i);l.replaceRange(f.text+"\n",{line:i,ch:0},{line:i,ch:f.text.length+1}),n.foldCode(e.Pos(o,t.text.length)),n.foldCode(e.Pos(o,t.text.length))}}}));try{if("gutterMarkers"in i&&"CodeMirror-foldgutter"in i.gutterMarkers){let r=i.text;if(r.charAt(r.length-1)==t){let t=r.length;l.replaceRange(r.slice(0,-1),{line:o,ch:0},{line:o,ch:t}),n.foldCode(e.Pos(o,t-1),null,"unfold")}else{let i=r.length;l.replaceRange(r+t,{line:o,ch:0},{line:o,ch:i+1}),n.foldCode(e.Pos(o,i+1),null,"fold")}}}catch(e){console.log(e)}}function r(e,t){}function l(t,n,o){if(console.log(n,o),0==n&&o<300)for(var r=t.lastLine();r>=t.firstLine();--r){let n=t.getLine(r);if("#"==n.charAt(0)&&"."==n.charAt(n.length-1)){let o=t.getLineHandle(r);void 0!==o.gutterMarkers&&void 0!==o.gutterMarkers["CodeMirror-foldgutter"]&&void 0!==o.gutterMarkers["CodeMirror-foldgutter"].className&&o.gutterMarkers["CodeMirror-foldgutter"].className.includes("CodeMirror-foldgutter-folded")||t.foldCode(e.Pos(r,n.length),null,"fold")}}}function i(t,n){t.getDoc();for(var o=t.lastLine();o>=t.firstLine();--o){let n=t.getLine(o);if("#"==n.charAt(0)&&"."==n.charAt(n.length-1)){let n=t.getLineHandle(o);void 0!==n.gutterMarkers&&void 0!==n.gutterMarkers["CodeMirror-foldgutter"]&&void 0!==n.gutterMarkers["CodeMirror-foldgutter"].className&&n.gutterMarkers["CodeMirror-foldgutter"].className.includes("CodeMirror-foldgutter-folded")||t.foldCode(e.Pos(o,0))}}}e.defineExtension("persistentFolding",(function(){this.on("viewportChange",l),this.on("changes",r),this.on("focus",i),this.on("gutterClick",o),console.log("folding is activated")})),e.defineOption("enable-folding-mode",!1,(function(t,o,r){return n(this,void 0,void 0,(function*(){if(r&&r!=e.Init&&(t.off("change",i),t.off("update",i),t.off("viewportChange",i)),o){setTimeout((function(e){return n(this,void 0,void 0,(function*(){t.persistentFolding()}))}),150,100)}}))}))}e.exports={default:function(e){return{plugin:o,codeMirrorResources:["addon/fold/foldgutter","addon/fold/markdown-fold"],codeMirrorOptions:{foldGutter:!0,"enable-folding-mode":!0,gutters:["CodeMirror-foldgutter"]},assets:function(){return[{name:"foldgutter.css"}]}}}}}]).default;index.js000644 0000007515 14116141676007370 0ustar00000000 000000 !function(e){var t={};function n(o){if(t[o])return t[o].exports;var i=t[o]={i:o,l:!1,exports:{}};return e[o].call(i.exports,i,i.exports,n),i.l=!0,i.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(o,i,function(t){return e[t]}.bind(null,i));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t,n){"use strict";var o;Object.defineProperty(t,"__esModule",{value:!0}),t.ContentScriptType=t.SettingStorage=t.AppType=t.SettingItemType=t.ToolbarButtonLocation=t.isContextMenuItemLocation=t.MenuItemLocation=t.ImportModuleOutputFormat=t.FileSystemItem=void 0,function(e){e.File="file",e.Directory="directory"}(t.FileSystemItem||(t.FileSystemItem={})),function(e){e.Markdown="md",e.Html="html"}(t.ImportModuleOutputFormat||(t.ImportModuleOutputFormat={})),function(e){e.File="file",e.Edit="edit",e.View="view",e.Note="note",e.Tools="tools",e.Help="help",e.Context="context",e.NoteListContextMenu="noteListContextMenu",e.EditorContextMenu="editorContextMenu",e.FolderContextMenu="folderContextMenu",e.TagContextMenu="tagContextMenu"}(o=t.MenuItemLocation||(t.MenuItemLocation={})),t.isContextMenuItemLocation=function(e){return[o.Context,o.NoteListContextMenu,o.EditorContextMenu,o.FolderContextMenu,o.TagContextMenu].includes(e)},function(e){e.NoteToolbar="noteToolbar",e.EditorToolbar="editorToolbar"}(t.ToolbarButtonLocation||(t.ToolbarButtonLocation={})),function(e){e[e.Int=1]="Int",e[e.String=2]="String",e[e.Bool=3]="Bool",e[e.Array=4]="Array",e[e.Object=5]="Object",e[e.Button=6]="Button"}(t.SettingItemType||(t.SettingItemType={})),function(e){e.Desktop="desktop",e.Mobile="mobile",e.Cli="cli"}(t.AppType||(t.AppType={})),function(e){e[e.Database=1]="Database",e[e.File=2]="File"}(t.SettingStorage||(t.SettingStorage={})),function(e){e.MarkdownItPlugin="markdownItPlugin",e.CodeMirrorPlugin="codeMirrorPlugin"}(t.ContentScriptType||(t.ContentScriptType={}))},function(e,t,n){"use strict";var o=this&&this.__awaiter||function(e,t,n,o){return new(n||(n=Promise))((function(i,r){function l(e){try{a(o.next(e))}catch(e){r(e)}}function u(e){try{a(o.throw(e))}catch(e){r(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(l,u)}a((o=o.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const i=n(2),r=n(0),l=n(0);i.default.plugins.register({onStart:function(){return o(this,void 0,void 0,(function*(){yield i.default.contentScripts.register(r.ContentScriptType.CodeMirrorPlugin,"folding","./folding.js"),yield i.default.commands.register({name:"foldAllByPlugin",label:"Fold all ",execute:()=>o(this,void 0,void 0,(function*(){yield i.default.commands.execute("editor.execCommand",{name:"foldAllByPlugin",args:[]})}))}),yield i.default.commands.register({name:"unfoldAllByPlugin",label:"Unfold all ",execute:()=>o(this,void 0,void 0,(function*(){yield i.default.commands.execute("editor.execCommand",{name:"unfoldAllByPlugin",args:[]})}))}),yield i.default.views.menuItems.create("foldAllMenuItem","foldAllByPlugin",l.MenuItemLocation.Tools,{accelerator:"CmdOrCtrl+Alt+F"}),yield i.default.views.menuItems.create("unfoldAllMenuItem","unfoldAllByPlugin",l.MenuItemLocation.Tools,{accelerator:"CmdOrCtrl+Alt+U"})}))}})},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.default=joplin}]);manifest.json000644 0000000657 14116141676010424 0ustar00000000 000000 { "manifest_version": 1, "id": "joplin.plugin.ambrt.fold-cm", "app_min_version": "1.7", "version": "2.0.1", "name": "Folding in Code Mirror Editor", "description": "Allows to fold parts of markdown text displayed in editor", "author": "ambrt", "homepage_url": "https://discourse.joplinapp.org/t/persistent-text-folding-in-editor/16183", "repository_url": "https://github.com/ambrt/joplin-plugin-fold-cm", "keywords": [] }