Creating a basic website to assist in editing .filter files for Path of Exile, I have integrated CodeMirror and developed a custom mode to manage syntax highlighting using the mode/simple.js addon. Currently, I am working on incorporating code folding based on indentation.
Despite exploring the examples and documentation available on the CodeMirror website:
My searches on Stack Overflow yielded minimal results related to my issue, leading me to thoroughly review my work based on the solutions found in a single relevant thread here: CodeMirror foldCode method not working
However, the error persists. I even considered if the addon is incompatible with custom/simple modes, yet the online resources are lacking in both quality and quantity of information about CodeMirror.
I would greatly appreciate any assistance in resolving this matter. Additionally, if anyone is aware of high-quality tutorials on this subject, please share them.
Here's the structure of the HTML file:
<html lang="en">
<head>
<meta charset="utf-8">
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title>Filter Editor</title>
<meta name="description" content="HTML Editor for PoE Filters">
<meta name="author" content="author">
<link href="https://fonts.googleapis.com/css?family=Roboto&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/styles.css">
<link rel="stylesheet" href="codemirror/lib/codemirror.css">
<link rel="stylesheet" href="codemirror/theme/twilight.css">
<link rel="stylesheet" href="codemirror/addon/fold/foldgutter.css">
</head>
<body>
<div id='app-container'>
<div id='display-pane'>
<!-- Include your content here -->
</div>
<div id='editor-pane'>
<!-- Include your CodeMirror editor here -->
</div>
</div>
<script src="js/jquery.min.js"></script>
<script src="codemirror/lib/codemirror.js"></script>
<script src="codemirror/addon/fold/foldcode.js"></script>
<script src="codemirror/addon/fold/foldgutter.js"></script>
<script src="codemirror/addon/fold/indent-fold.js"></script>
<script src="codemirror/addon/mode/simple.js"></script>
<script src="codemirror/mode/filter/poefilter.js"></script>
<script src="js/scripts.js"></script>
</body>
</html>
Below is the JavaScript where I initialize the CodeMirror instance:
$(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%");
Here's the custom mode (poefilter.js) that I've written:
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", {
start: [
{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"
});
The expected outcome includes clickable arrows in the gutter for folding and unfolding sections of the code. Instead, there are no arrows visible, and an error appears in the developer console indicating:
scripts.js:19 Uncaught TypeError: CodeMirror.foldcode is not a function