Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/web/js/beforePyret.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ $(function() {
$("#download").append(downloadElt);
});

const CONTEXT_PREFIX = "use context ";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be /^use context\s+/, so that the .slice on line 498 trims any interstitial whitespace between the context and the actual context value.

Actually, could you reuse firstLineIsNamespace from beforePyret, and expose it along with setContextLine, at

setContextLine: setContextLine,
, so that you can just do CPO.editor.firstLineIsNamespace? You'd fix up the regex on line 225, (it shouldn't end in .*, but rather \s+. Then maybe refactor lines 495-498 of your code below into a function getContextFromFirstLine() that is likewise made available?


function showModal(currentContext) {
function drawElement(input) {
const element = $("<div>");
Expand Down Expand Up @@ -485,11 +487,18 @@ $(function() {
});
namespaceResult.show((result) => {
if(!result) { return; }
if(result.match(/^use context*/)) { result = result.slice("use context ".length); }
CPO.editor.setContextLine("use context " + result + "\n");
if(result.startsWith(CONTEXT_PREFIX)) { result = result.slice(CONTEXT_PREFIX.length); }
CPO.editor.setContextLine(CONTEXT_PREFIX + result + "\n");
});
}
$("#choose-context").on("click", function() { showModal(CPO.editor.cm.getLine(0).slice("use context ".length)); });
$("#choose-context").on("click", function() {
let currentContext = "";
let firstLine = CPO.editor.cm.getLine(0);
if(firstLine.startsWith(CONTEXT_PREFIX)) {
currentContext = firstLine.slice(CONTEXT_PREFIX.length);
}
showModal(currentContext);
});

var TRUNCATE_LENGTH = 20;

Expand Down