Javascript 我不断地得到;CodeMirror.foldCode不是函数;。代码折叠插件是否不适用于自定义/简单模式?
我正在写一个非常基本的网站来帮助我编辑。过滤文件,寻找流放之路。我正在使用CodeMirro,并且已经编写了一个自定义模式来使用mode/simple.js插件处理语法高亮显示。现在,我尝试实现基于缩进的代码折叠 我浏览了CodeMirror网站上提供的示例和文档。 我在这里搜索了这么久,发现很少有结果与我的问题有直接关系。我已经根据这里找到的一个匹配项提供的解决方案仔细检查了我的工作。 但我仍然得到了错误。我试着研究这个插件是否不能在自定义/简单模式下工作,但似乎互联网严重缺乏关于CodeMirror的信息的质量和数量 如果您能帮助解决此问题,我们将不胜感激。另外,如果有人知道我在哪里可以找到一些高质量的教程,那将是令人惊讶的 html: 以下是我编写的模式(poefilter.js):Javascript 我不断地得到;CodeMirror.foldCode不是函数;。代码折叠插件是否不适用于自定义/简单模式?,javascript,codemirror,add-on,code-folding,Javascript,Codemirror,Add On,Code Folding,我正在写一个非常基本的网站来帮助我编辑。过滤文件,寻找流放之路。我正在使用CodeMirro,并且已经编写了一个自定义模式来使用mode/simple.js插件处理语法高亮显示。现在,我尝试实现基于缩进的代码折叠 我浏览了CodeMirror网站上提供的示例和文档。 我在这里搜索了这么久,发现很少有结果与我的问题有直接关系。我已经根据这里找到的一个匹配项提供的解决方案仔细检查了我的工作。 但我仍然得到了错误。我试着研究这个插件是否不能在自定义/简单模式下工作,但似乎互联网严重缺乏关于Code
var测试={
块:/(?:显示|隐藏)/,
条件:/(?:ItemLevel | DropLevel | Quality | Rarity | Class | Sockets | LinkedSockets | SocketGroup | Height | Width | anyenchanment | StackSize | GemLevel | idem | idem | ShaperItem | fracteditem | synthedItem ShapedMap | ShapedMap,
opencond:/BaseType | Prophecy | HasExplicitMod | hasEnchanment | CustomAlertSound/,
动作:/(?:SetBordColor | SetTextColor | SetBackgroundColor | SetFontSize | PlayAlertSound位置| PlayAlertSound | DisableDropSound | MinimapIcon | PlayEffect)/,
运算符:/(?:=)/,
编号:/[0-9]+/,
文字:/(?:真|假|正常|魔法|稀有|独特|温度|红色|绿色|蓝色|黄色|棕色|白色|三角形|方形|圆形|钻石|六边形| R | G | B)/,
物品类别:/(?:“生命瓶”;“魔法瓶”;“混合瓶”;“实用瓶”;“关键实用瓶”;“可堆叠货币”;“可堆叠货币”;“可堆叠货币”;“可堆叠货币”;“货币”;“护身符”;“戒指”;“爪子”;“符文匕首”;“单手匕首”;“单手插剑”;“两手剑”;“双手斧头”;“一把剑”;“一把剑”;“一把剑”;“一把剑”;“一把剑”;“两把剑”;“两把剑”;“两把剑”;“两把剑”|“一手手锏”轴数数??;“一手锏”轴数???????????????????????????????????????????????????????????????????????????????????????;轴轴轴轴轴轴数数数数数轴轴轴数数数数数数轴轴轴数数数数轴数数轴数数数数轴数???????????????????????????????????????????????????????????????????????????????????????????????“迷宫物品”|“迷宫饰品”|“迷宫地图项目”|迷宫|“杂项地图项目”|联盟石|“万神殿灵魂”|碎片|“入侵项目”|孵化器|“碎片心脏”|碎片|地图|地图)/,
注释:/#。*/,
海关:/*/
}
CodeMirror.defineSimpleMode(“poefilter”{
//开始状态包含初始使用的规则
开始:[
//块
{regex:test.comment,标记:[“comment”]},
{regex:test.block,标记:“header”},
{regex:test.condition,标记:“属性”},
{regex:test.opencond,token:“attribute”,next:“custom”},
{regex:test.action,标记:“def”},
{regex:test.operators,标记:“operator”},
{regex:test.number,标记:“number”},
{regex:test.itemclass,标记:“string-2”},
{regex:test.literal,标记:“number”}
],
自定义:[
{regex:test.custom,标记:“string”,下一步:“start”}
],
折叠:“poefilter”
});
我希望看到槽中的小箭头,允许我单击它们来折叠打开和折叠关闭代码。相反,我没有看到箭头,我在开发人员控制台中得到一个错误,说:
scripts.js:19未捕获类型错误:CodeMirror.foldcode不是函数
好的,我终于解决了这个问题
模式文件的最后一行,折叠:“poefilter”有一些问题
首先,“poefilter”
应该是“indent”
,因为这是我试图用foldcode插件(通过indent fold.js)应用的折叠类型的名称
其次,由于我使用的是简单模式,因此需要将选项包装在meta属性中,如下所示:
meta: {
fold: "indent"
}
一旦我解决了这两个问题,一切都很顺利。你可能会幸运地找到答案
$(document).ready(function() {
// CodeMirror Stuff
var code = $("#code-mirror")[0];
var editor = CodeMirror.fromTextArea(code, {
mode: "poefilter",
theme: "twilight",
lineNumbers: true,
lineWrapping: true,
viewportMargin: 30,
// saveFunction: "saveFunction",
indentUnit: 4,
minHeight: "100%",
extraKeys: {"Ctrl-Q": function(cm){ CodeMirror.foldCode(cm.getCursor()); }},
foldGutter: true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
});
editor.foldCode(CodeMirror.Pos(0, 0));
editor.setSize("100%", "100%");
var test = {
block: /(?:Show|Hide)/,
condition: /(?:ItemLevel|DropLevel|Quality|Rarity|Class|Sockets|LinkedSockets|SocketGroup|Height|Width|AnyEnchantment|StackSize|GemLevel|Identified|Corrupted|ElderItem|ShaperItem|FracturedItem|SynthesisedItem|ShapedMap|BlightedMap|MapTier)/,
opencond: /BaseType|Prophecy|HasExplicitMod|HasEnchantment|CustomAlertSound/,
action: /(?:SetBorderColor|SetTextColor|SetBackgroundColor|SetFontSize|PlayAlertSoundPositional|PlayAlertSound|DisableDropSound|MinimapIcon|PlayEffect)/,
operators: /(?:<|<=|=|>|>=)/,
number: /[0-9]+/,
literal: /(?:True|False|Normal|Magic|Rare|Unique|Temp|Red|Green|Blue|Yellow|Brown|White|Triangle|Square|Circle|Diamond|Hexagon|R|G|B)/,
itemclass: /(?:"Life Flasks"|"Mana Flasks"|"Hybrid Flasks"|"Utility Flasks"|"Critical Utility Flasks"|Flasks|"Stackable Currency"|"Delve Stackable Socketable Currency"|"Socketable Currency"|Currency|Amulets|Rings|Claws|"Rune Dagger"|Daggers|Wands|"One Hand Swords"|"Thrusting One Hand Swords"|"Two Hand Swords"|Swords|"One Hand Axes"|"Two Hand Axes"|Axes|"One Hand Maces"|"Two Hand Maces"|Maces|Bows|Quivers|Staves|Warstaff|"Active Skill Gems"|"Support Skill Gems"|Gems|Belts|Gloves|Boots|"Body Armours"|Body|Helmets|Shields|"Quest Items"|Sceptres|Unarmed|"Fishing Rods"|"Map Fragments"|"Hideout Doodads"|Microtransactions|"Abyss Jewel"|Jewel|"Divination Card"|"Labyrinth Item"|"Labyrinth Trinket"|"Labyrinth Map Item"|Labyrinth|"Misc Map Items"|Leaguestones|"Pantheon Soul"|Piece|"Incursion Item"|Incubator|"Shard Heart"|Shard|Maps|Map)/,
comment: /#.*/,
custom: /.*/
}
CodeMirror.defineSimpleMode("poefilter", {
// The start state contains the rules that are intially used
start: [
// blocks
{regex: test.comment, token: ["comment"]},
{regex: test.block, token: "header"},
{regex: test.condition, token: "attribute"},
{regex: test.opencond, token: "attribute", next: "custom"},
{regex: test.action, token: "def"},
{regex: test.operators, token: "operator"},
{regex: test.number, token: "number"},
{regex: test.itemclass, token: "string-2"},
{regex: test.literal, token: "number"}
],
custom: [
{regex: test.custom, token: "string", next: "start"}
],
fold: "poefilter"
});
meta: {
fold: "indent"
}