From c62b50ffd0ace3d7cc8f3cf7d18d42b1ccf5ede9 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Mon, 24 Oct 2022 08:12:10 +0200 Subject: [PATCH] feat(#134): add support for line highlighting in code --- public/css/style.css | 6 ++++++ public/script/app.js | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/public/css/style.css b/public/css/style.css index 52d515e..06a54ed 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -560,4 +560,10 @@ loc .lang { .org-subscript-child { font-size: 85%; +} + +.highlighted-line { + position:absolute; + background:rgba(100,200,100,0.5); + z-index:20 } \ No newline at end of file diff --git a/public/script/app.js b/public/script/app.js index d4a8dd4..7da80b8 100644 --- a/public/script/app.js +++ b/public/script/app.js @@ -1478,6 +1478,25 @@ angular mode: getMode(extension), onLoad: function (_editor) { + if (window.location.hash && window.location.hash.match(/^#L\d+/)) { + let from = 0; + let to = 0; + if (window.location.hash.indexOf('-') > -1) { + const match = window.location.hash.match(/^#L(\d+)-L(\d+)/); + from = parseInt(match[1]) - 1; + to = parseInt(match[2]) - 1; + } else { + from = parseInt(window.location.hash.substring(2)) - 1; + to = from; + } + + const Range = ace.require('ace/range').Range; + _editor.session.addMarker(new Range(from, 0, to, 1), "highlighted-line", "fullLine"); + setTimeout(() => { + _editor.scrollToLine(from, true, true, function () {}); + }, 100); + } + _editor.setFontSize($scope.aceOption.fontSize); _editor.setReadOnly($scope.aceOption.readOnly); _editor.setKeyboardHandler($scope.aceOption.keyBinding);