Skip to content

Conversation

@asolove
Copy link
Contributor

@asolove asolove commented Mar 13, 2024

Fixes #399

Previously, if your first line wasn't a use context declaration, the Choose Context modal would just grab an arbitrary substring of your first line, resulting in gibberish.

This change first checks if the first line is actually a use context. If so, it shows the current context. If not, it shows the current context as blank and lets you enter a new one.

Previously, if your first line wasn't a use context declaration, the Choose Context modal would just grab an arbitrary substring of your first line, resulting in gibberish.

This change first checks if the first line is a use context. If so, it shows the current context. If not, it shows the current context as blank and lets you enter a new one.
Copy link
Member

@blerner blerner left a comment

Choose a reason for hiding this comment

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

LGTM, just some minor refactoring to make it less repetitive with existing code.

$("#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?

blerner pushed a commit that referenced this pull request May 9, 2024
Is more restrictive about guessing when the first line is a context line, and trims the context name of leading/trailing spaces as well.
@blerner blerner closed this May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Choosing context on a file with no context line substrings into whatever is there

2 participants