-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: select text when opening find/replace #1516
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -159,7 +163,10 @@ function splitQuotePrefix(quote: string): [PrefixKind, string] { | |||
); | |||
for (const prefix of prefixKindsByLength) { | |||
if (quote.startsWith(prefix)) { | |||
return [prefix, quote.slice(prefix.length)]; | |||
const remaining = quote.slice(prefix.length); | |||
if (remaining.startsWith('"""') || remaining.startsWith('"')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want this? i would expect '''
and '
to be valid as well?
@@ -38,13 +38,16 @@ const regexes = pairs.map( | |||
] as const, | |||
); | |||
|
|||
type QuoteType = '"' | '"""'; // Define a type that restricts to either single or triple quotes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think '
and '''
are valid as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if its not too much trouble, could we add some tests to markdown.test.ts
?
describe("should not modify original code when going in and out", () => {
const cases = [
'mo.md("""# Markdown Title\n\nSome content here.""")',
'mo.md("Some *markdown* content")',
"mo.md('''# Another Title\nContent''')",
'mo.md(f"""This is some \\"""content\\"""!""")',
'mo.md("""This is some \\"""content\\"""!""")',
'mo.md("This is some \\"content\\"!")',
"mo.md('This is some \\'content\\'!')",
'mo.md("""Markdown with an escaped \\"quote\\"""")',
'mo.md("""# Title\n\n```python\nprint("Hello, Markdown!")\n```""")',
'mo.md("")',
'mo.md("# Title without proper delimiters")',
'mo.md(""" \n# Title\nContent\n """)',
];
it.each(cases)("should not modify %s", (pythonCode) => {
const [innerCode] = adapter.transformIn(pythonCode);
const [wrappedCode] = adapter.transformOut(innerCode);
expect(pythonCode).toBe(wrappedCode);
});
});
there is also a case where we cannot keep the QuoteType
. like when we go from single-line to multi-line, we need to upgrade from single-quote to multi-quote. we should make sure that is handled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basically - i don't think we want to downgrade from a """
to "
it if was previously a """
. but we do want to upgrade to """
, if the markdown becomes multi-line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basically - i don't think we want to downgrade from a
"""
to"
it if was previously a"""
. but we do want to upgrade to"""
, if the markdown becomes multi-line
yeah, this is what i intend to do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think
'
and'''
are valid as well
i should've considered these two cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if its not too much trouble, could we add some tests to
markdown.test.ts
?describe("should not modify original code when going in and out", () => { const cases = [ 'mo.md("""# Markdown Title\n\nSome content here.""")', 'mo.md("Some *markdown* content")', "mo.md('''# Another Title\nContent''')", 'mo.md(f"""This is some \\"""content\\"""!""")', 'mo.md("""This is some \\"""content\\"""!""")', 'mo.md("This is some \\"content\\"!")', "mo.md('This is some \\'content\\'!')", 'mo.md("""Markdown with an escaped \\"quote\\"""")', 'mo.md("""# Title\n\n```python\nprint("Hello, Markdown!")\n```""")', 'mo.md("")', 'mo.md("# Title without proper delimiters")', 'mo.md(""" \n# Title\nContent\n """)', ]; it.each(cases)("should not modify %s", (pythonCode) => { const [innerCode] = adapter.transformIn(pythonCode); const [wrappedCode] = adapter.transformOut(innerCode); expect(pythonCode).toBe(wrappedCode); }); });there is also a case where we cannot keep the
QuoteType
. like when we go from single-line to multi-line, we need to upgrade from single-quote to multi-quote. we should make sure that is handled
yeah, i'll add more tests
findInputRef.current.focus(); // Focus the input | ||
findInputRef.current.select(); // Select all text in the input | ||
} | ||
}, [state.isOpen]); // Depend on isOpen to trigger when the panel opens |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome! nice touch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome! thanks for the PR
📝 Summary
Fixes #1506
🔍 Description of Changes
📋 Checklist
📜 Reviewers
@akshayka OR @mscolnick