Skip to content

Commit

Permalink
Merge pull request #50 from martialblog/feature/update-editor
Browse files Browse the repository at this point in the history
Update CodeMirror and some CSS fixes
  • Loading branch information
martialblog committed Jun 12, 2024
2 parents 8cd5b62 + c690d87 commit 05b1666
Show file tree
Hide file tree
Showing 25 changed files with 10,609 additions and 9,459 deletions.
3 changes: 3 additions & 0 deletions application/forms/EditForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public function createElements(array $formData)
array(
'ignore' => true,
'label' => $this->translate('Cancel editing'),
'class' => 'btn-cancel',
'decorators' => array('ViewHelper')
)
);
Expand All @@ -168,6 +169,8 @@ public function createElements(array $formData)
array(
'ignore' => true,
'label' => $this->translate('Delete config'),
'class' => 'btn-remove',
'onclick' => 'return confirm("' . $this->translate('Confirm deletion') . '")',
'decorators' => array('ViewHelper')
)
);
Expand Down
Binary file modified application/locale/de_DE/LC_MESSAGES/toplevelview.mo
Binary file not shown.
12 changes: 8 additions & 4 deletions application/locale/de_DE/LC_MESSAGES/toplevelview.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ msgstr ""
"Project-Id-Version: Toplevelview Module (0.0.0)\n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2017-10-13 11:53+0000\n"
"PO-Revision-Date: 2017-10-13 14:00+0200\n"
"PO-Revision-Date: 2024-04-24 12:51+0200\n"
"Last-Translator: Markus Opolka <[email protected]>\n"
"Language-Team: \n"
"Language: de_DE\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-Basepath: .\n"
"Last-Translator: Markus Frosch <[email protected]>\n"
"Language-Team: \n"
"X-Generator: Poedit 1.8.11\n"
"X-Generator: Poedit 3.0.1\n"
"X-Poedit-SearchPath-0: .\n"

#: ../../../../modules/toplevelview/application/views/helpers/Tree.php:58
Expand Down Expand Up @@ -161,3 +161,7 @@ msgstr "Nicht-Gespeicherte Änderungen!"
#: ../../../../modules/toplevelview/application/forms/EditForm.php:120
msgid "YAML Config"
msgstr "YAML Konfiguration"

#: ../../../../modules/toplevelview/application/forms/EditForm.php:173
msgid "Confirm deletion"
msgstr "Löschen bestätigen"
6 changes: 0 additions & 6 deletions application/views/scripts/show/actions.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,4 @@
}
}
?>
<?php if ($view->hasBeenLoadedFromSession()): ?>
<div class="warning-note">
<?= $this->translate('This config is only stored in your session!'
. ' Make sure to save it to disk once your work is complete!') ?>
</div>
<?php endif; ?>
</div>
6 changes: 6 additions & 0 deletions application/views/scripts/show/index.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ if (! $this->compact):
</div>
<?php endif ?>
<div class="content tlv-content">
<?php if ($view->hasBeenLoadedFromSession()): ?>
<div class="warning-note">
<?= $this->translate('This config is only stored in your session!'
. ' Make sure to save it to disk once your work is complete!') ?>
</div>
<?php endif; ?>
<div class="tlv-header">
<?= $this->badges($tree->getStatus(), false, true) ?>
<h1><?= $view->getMeta('name') ?></h1>
Expand Down
4 changes: 4 additions & 0 deletions configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
$this->provideJsFile('vendor/codemirror/addon/search/search.js');
$this->provideJsFile('vendor/codemirror/addon/search/matchesonscrollbar.js');
$this->provideJsFile('vendor/codemirror/addon/search/jump-to-line.js');
$this->provideJsFile('vendor/codemirror/addon/fold/foldcode.js');
$this->provideJsFile('vendor/codemirror/addon/fold/foldgutter.js');
$this->provideJsFile('vendor/codemirror/addon/fold/indent-fold.js');

$this->provideCssFile('vendor/codemirror/codemirror.css');
$this->provideCssFile('vendor/codemirror/addon/dialog/dialog.css');
$this->provideCssFile('vendor/codemirror/addon/search/matchesonscrollbar.css');
$this->provideCssFile('vendor/codemirror/addon/fold/foldgutter.css');
17 changes: 6 additions & 11 deletions public/css/module.less
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,12 @@
content: '\e81d';
}

.collapsed {
}

.tlv-collapsed {
.icon.tlv-collapse-handle::before {
content: '\e820';
content: '\e820';
}
}
}

/** BEGIN of breadcrumb **/
Expand Down Expand Up @@ -497,18 +498,12 @@
}

.warning-note {
display: inline-block;

padding: 1px 5px;
padding: 0.5em;
margin: 0.5em;
background: @tlv-color-warning-bg;
color: @tlv-color-warning-fg
}

textarea.code-editor {
min-height: 45em;
width: 100%;
}

.CodeMirror {
min-height: 60em;
width: 100%;
Expand Down
20 changes: 20 additions & 0 deletions public/css/vendor/codemirror/addon/fold/foldgutter.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.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-foldgutter-open:after {
content: "\25BE";
}
.CodeMirror-foldgutter-folded:after {
content: "\25B8";
}
4 changes: 3 additions & 1 deletion public/js/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
var mode = el.getAttribute('data-codemirror-mode');
var editor = CodeMirror.fromTextArea(el, {
lineNumbers: true,
mode: mode
mode: mode,
foldGutter: true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"]
});
// avoid entering tab chars
editor.setOption('extraKeys', {
Expand Down
2 changes: 1 addition & 1 deletion public/js/vendor/codemirror/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.30.0
5.65.16
10 changes: 8 additions & 2 deletions public/js/vendor/codemirror/addon/dialog/dialog.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
// Distributed under an MIT license: https://codemirror.net/5/LICENSE

// Open simple dialogs on top of an editor. Relies on dialog.css.

Expand All @@ -25,6 +25,7 @@
} else { // Assuming it's a detached DOM element.
dialog.appendChild(template);
}
CodeMirror.addClass(wrap, 'dialog-opened');
return dialog;
}

Expand All @@ -47,6 +48,7 @@
} else {
if (closed) return;
closed = true;
CodeMirror.rmClass(dialog.parentNode, 'dialog-opened');
dialog.parentNode.removeChild(dialog);
me.focus();

Expand Down Expand Up @@ -80,7 +82,9 @@
if (e.keyCode == 13) callback(inp.value, e);
});

if (options.closeOnBlur !== false) CodeMirror.on(inp, "blur", close);
if (options.closeOnBlur !== false) CodeMirror.on(dialog, "focusout", function (evt) {
if (evt.relatedTarget !== null) close();
});
} else if (button = dialog.getElementsByTagName("button")[0]) {
CodeMirror.on(button, "click", function() {
close();
Expand All @@ -102,6 +106,7 @@
function close() {
if (closed) return;
closed = true;
CodeMirror.rmClass(dialog.parentNode, 'dialog-opened');
dialog.parentNode.removeChild(dialog);
me.focus();
}
Expand Down Expand Up @@ -141,6 +146,7 @@
if (closed) return;
closed = true;
clearTimeout(doneTimer);
CodeMirror.rmClass(dialog.parentNode, 'dialog-opened');
dialog.parentNode.removeChild(dialog);
}

Expand Down
119 changes: 119 additions & 0 deletions public/js/vendor/codemirror/addon/fold/brace-fold.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: https://codemirror.net/5/LICENSE

(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

function bracketFolding(pairs) {
return function(cm, start) {
var line = start.line, lineText = cm.getLine(line);

function findOpening(pair) {
var tokenType;
for (var at = start.ch, pass = 0;;) {
var found = at <= 0 ? -1 : lineText.lastIndexOf(pair[0], at - 1);
if (found == -1) {
if (pass == 1) break;
pass = 1;
at = lineText.length;
continue;
}
if (pass == 1 && found < start.ch) break;
tokenType = cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1));
if (!/^(comment|string)/.test(tokenType)) return {ch: found + 1, tokenType: tokenType, pair: pair};
at = found - 1;
}
}

function findRange(found) {
var count = 1, lastLine = cm.lastLine(), end, startCh = found.ch, endCh
outer: for (var i = line; i <= lastLine; ++i) {
var text = cm.getLine(i), pos = i == line ? startCh : 0;
for (;;) {
var nextOpen = text.indexOf(found.pair[0], pos), nextClose = text.indexOf(found.pair[1], pos);
if (nextOpen < 0) nextOpen = text.length;
if (nextClose < 0) nextClose = text.length;
pos = Math.min(nextOpen, nextClose);
if (pos == text.length) break;
if (cm.getTokenTypeAt(CodeMirror.Pos(i, pos + 1)) == found.tokenType) {
if (pos == nextOpen) ++count;
else if (!--count) { end = i; endCh = pos; break outer; }
}
++pos;
}
}

if (end == null || line == end) return null
return {from: CodeMirror.Pos(line, startCh),
to: CodeMirror.Pos(end, endCh)};
}

var found = []
for (var i = 0; i < pairs.length; i++) {
var open = findOpening(pairs[i])
if (open) found.push(open)
}
found.sort(function(a, b) { return a.ch - b.ch })
for (var i = 0; i < found.length; i++) {
var range = findRange(found[i])
if (range) return range
}
return null
}
}

CodeMirror.registerHelper("fold", "brace", bracketFolding([["{", "}"], ["[", "]"]]));

CodeMirror.registerHelper("fold", "brace-paren", bracketFolding([["{", "}"], ["[", "]"], ["(", ")"]]));

CodeMirror.registerHelper("fold", "import", function(cm, start) {
function hasImport(line) {
if (line < cm.firstLine() || line > cm.lastLine()) return null;
var start = cm.getTokenAt(CodeMirror.Pos(line, 1));
if (!/\S/.test(start.string)) start = cm.getTokenAt(CodeMirror.Pos(line, start.end + 1));
if (start.type != "keyword" || start.string != "import") return null;
// Now find closing semicolon, return its position
for (var i = line, e = Math.min(cm.lastLine(), line + 10); i <= e; ++i) {
var text = cm.getLine(i), semi = text.indexOf(";");
if (semi != -1) return {startCh: start.end, end: CodeMirror.Pos(i, semi)};
}
}

var startLine = start.line, has = hasImport(startLine), prev;
if (!has || hasImport(startLine - 1) || ((prev = hasImport(startLine - 2)) && prev.end.line == startLine - 1))
return null;
for (var end = has.end;;) {
var next = hasImport(end.line + 1);
if (next == null) break;
end = next.end;
}
return {from: cm.clipPos(CodeMirror.Pos(startLine, has.startCh + 1)), to: end};
});

CodeMirror.registerHelper("fold", "include", function(cm, start) {
function hasInclude(line) {
if (line < cm.firstLine() || line > cm.lastLine()) return null;
var start = cm.getTokenAt(CodeMirror.Pos(line, 1));
if (!/\S/.test(start.string)) start = cm.getTokenAt(CodeMirror.Pos(line, start.end + 1));
if (start.type == "meta" && start.string.slice(0, 8) == "#include") return start.start + 8;
}

var startLine = start.line, has = hasInclude(startLine);
if (has == null || hasInclude(startLine - 1) != null) return null;
for (var end = startLine;;) {
var next = hasInclude(end + 1);
if (next == null) break;
++end;
}
return {from: CodeMirror.Pos(startLine, has + 1),
to: cm.clipPos(CodeMirror.Pos(end))};
});

});
59 changes: 59 additions & 0 deletions public/js/vendor/codemirror/addon/fold/comment-fold.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: https://codemirror.net/5/LICENSE

(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";

CodeMirror.registerGlobalHelper("fold", "comment", function(mode) {
return mode.blockCommentStart && mode.blockCommentEnd;
}, function(cm, start) {
var mode = cm.getModeAt(start), startToken = mode.blockCommentStart, endToken = mode.blockCommentEnd;
if (!startToken || !endToken) return;
var line = start.line, lineText = cm.getLine(line);

var startCh;
for (var at = start.ch, pass = 0;;) {
var found = at <= 0 ? -1 : lineText.lastIndexOf(startToken, at - 1);
if (found == -1) {
if (pass == 1) return;
pass = 1;
at = lineText.length;
continue;
}
if (pass == 1 && found < start.ch) return;
if (/comment/.test(cm.getTokenTypeAt(CodeMirror.Pos(line, found + 1))) &&
(found == 0 || lineText.slice(found - endToken.length, found) == endToken ||
!/comment/.test(cm.getTokenTypeAt(CodeMirror.Pos(line, found))))) {
startCh = found + startToken.length;
break;
}
at = found - 1;
}

var depth = 1, lastLine = cm.lastLine(), end, endCh;
outer: for (var i = line; i <= lastLine; ++i) {
var text = cm.getLine(i), pos = i == line ? startCh : 0;
for (;;) {
var nextOpen = text.indexOf(startToken, pos), nextClose = text.indexOf(endToken, pos);
if (nextOpen < 0) nextOpen = text.length;
if (nextClose < 0) nextClose = text.length;
pos = Math.min(nextOpen, nextClose);
if (pos == text.length) break;
if (pos == nextOpen) ++depth;
else if (!--depth) { end = i; endCh = pos; break outer; }
++pos;
}
}
if (end == null || line == end && endCh == startCh) return;
return {from: CodeMirror.Pos(line, startCh),
to: CodeMirror.Pos(end, endCh)};
});

});
Loading

0 comments on commit 05b1666

Please sign in to comment.