Skip to content
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

InsertQuoteAction overwrites trailing character after token instead of closing double quote in Python #539

Closed
paul-griffith opened this issue Mar 22, 2024 · 2 comments
Assignees
Labels
Milestone

Comments

@paul-griffith
Copy link
Contributor

Description
In (at least) Python syntax highlighting, the character after the quote you just closed can be removed/overwritten.
Kapture 2024-03-22 at 08 30 38

<speculation>
This appears to be caused by the token maker. In the exact same scenario for Java, there will be a token "something with a type of ERROR_STRING_DOUBLE. But for Python, you get a token "something with a type of LITERAL_STRING_DOUBLE_QUOTE. This leads to a different branch in InsertQuoteAction, specifically this one:

			if (tokenType == quoteType.validTokenType) {
				if (offs == t.getEndOffset() - 1) {
					textArea.moveCaretPosition(offs + 1); // Force a replacement to ensure undo is contiguous
					textArea.replaceSelection(stringifiedQuoteTypeCh);
					textArea.setCaretPosition(offs + 1);
				}

This seems to be the cause of the issue, with the root being the token type spit out by the token maker.
</speculation>

Steps to Reproduce

  1. Type a string such as str("something) into an RSyntaxTextArea with Python syntax highlighting.
  2. Set the caret position between g and ).
  3. Enter a double quote.

Here's a test case that reproduces in RSyntaxTextAreaEditorKitInsertQuoteActionTest:

	@Test
	void testActionPerformedImpl_python_close_quote_overtypes() {
		String origContent = "call(\"function)";

		RSyntaxTextArea textArea = createTextArea(SyntaxConstants.SYNTAX_STYLE_PYTHON, origContent);
		textArea.setCaretPosition(origContent.indexOf("function") + 8);

		RecordableTextAction a = new RSyntaxTextAreaEditorKit.InsertQuoteAction("test",
			RSyntaxTextAreaEditorKit.InsertQuoteAction.QuoteType.DOUBLE_QUOTE);
		ActionEvent e = createActionEvent(textArea, "\"");
		a.actionPerformedImpl(e, textArea);

		Assertions.assertEquals("call(\"function\")", textArea.getText());
	}

Expected behavior
Double quotes should be closed 'correctly' without overtyping.

I'll also note, for the sake of it, that single quotes work just fine.

@paul-griffith
Copy link
Contributor Author

For a simple workaround (since my application will only ever be using Python in these editors), I'm simply overwriting the entry in the action map with base InsertPairedCharacterAction behavior:

put(
    RSyntaxTextAreaEditorKit.rstaDoubleQuoteAction,
    InsertPairedCharacterAction(RSyntaxTextAreaEditorKit.rstaDoubleQuoteAction, '"', '"')
)

@bobbylight bobbylight self-assigned this Jun 9, 2024
@bobbylight bobbylight added this to the 3.4.1 milestone Jun 9, 2024
@bobbylight
Copy link
Owner

Thanks for the bug report! This will be fixed in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants