This is an automated email from the ASF dual-hosted git repository. tmysik pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push: new ef75e380c7 Fix an issue that whitespace cannot be added #5707 new 067b11a242 Merge pull request #5710 from junichi11/php-gh-5707-cannot-add-space ef75e380c7 is described below commit ef75e380c7a49964500f96d4fbe3231dc3a99f22 Author: Junichi Yamamoto <junich...@apache.org> AuthorDate: Fri Mar 24 19:48:02 2023 +0900 Fix an issue that whitespace cannot be added #5707 - https://github.com/apache/netbeans/issues/5707 - Fix the deprecated methods --- .../typinghooks/PhpTypedTextInterceptor.java | 35 +++++++++++++-------- .../typinghooks/PhpTypedTextInterceptorTest.java | 36 ++++++++++++++++++++++ 2 files changed, 58 insertions(+), 13 deletions(-) diff --git a/php/php.editor/src/org/netbeans/modules/php/editor/typinghooks/PhpTypedTextInterceptor.java b/php/php.editor/src/org/netbeans/modules/php/editor/typinghooks/PhpTypedTextInterceptor.java index b3a2c1322d..d6d92c3ee0 100644 --- a/php/php.editor/src/org/netbeans/modules/php/editor/typinghooks/PhpTypedTextInterceptor.java +++ b/php/php.editor/src/org/netbeans/modules/php/editor/typinghooks/PhpTypedTextInterceptor.java @@ -183,7 +183,7 @@ public class PhpTypedTextInterceptor implements TypedTextInterceptor { if (ts != null) { ts.move(dotPos); if (ts.moveNext() && (ts.offset() < dotPos)) { - GsfUtilities.setLineIndentation(doc, dotPos, previousAdjustmentIndent); + GsfUtilities.setLineIndentation((Document) doc, dotPos, previousAdjustmentIndent); } } } @@ -450,29 +450,38 @@ public class PhpTypedTextInterceptor implements TypedTextInterceptor { int currentIndent = Utilities.getRowIndent(doc, offset); int newIndent = IndentUtils.countIndent(doc, offset, previousIndent); if (newIndent != currentIndent) { - GsfUtilities.setLineIndentation(doc, offset, Math.max(newIndent, 0)); + GsfUtilities.setLineIndentation((Document) doc, offset, Math.max(newIndent, 0)); } } else if (id == PHPTokenId.WHITESPACE || (id == PHPTokenId.PHP_TOKEN && token.text().charAt(0) == ':')) { // ":" handles "default:" + Token<? extends PHPTokenId> previousToken = null; if (id == PHPTokenId.WHITESPACE) { - LexUtilities.findPreviousToken(ts, Arrays.asList(PHPTokenId.PHP_CASE)); + previousToken = LexUtilities.findPreviousToken(ts, Arrays.asList(PHPTokenId.PHP_CASE, PHPTokenId.PHP_TOKEN)); } else { - LexUtilities.findPreviousToken(ts, Arrays.asList(PHPTokenId.PHP_DEFAULT)); + if (ts.movePrevious()) { // ":" + previousToken = LexUtilities.findPreviousToken(ts, Arrays.asList(PHPTokenId.PHP_DEFAULT, PHPTokenId.PHP_TOKEN)); + } } - if (ts.offset() >= rowFirstNonWhite) { //previous "case" or "default" on one line with typed char - LexUtilities.findPreviousToken(ts, Arrays.asList(PHPTokenId.PHP_SWITCH)); - Token<? extends PHPTokenId> firstCaseInSwitch = LexUtilities.findNextToken(ts, Arrays.asList(PHPTokenId.PHP_CASE)); - if (firstCaseInSwitch != null && firstCaseInSwitch.id() == PHPTokenId.PHP_CASE) { - int indentOfFirstCase = GsfUtilities.getLineIndent(doc, ts.offset()); - GsfUtilities.setLineIndentation(doc, offset, indentOfFirstCase); + if (ts.offset() >= rowFirstNonWhite + && previousToken != null + && (previousToken.id() == PHPTokenId.PHP_CASE + || previousToken.id() == PHPTokenId.PHP_DEFAULT)) { + // previous "case" or "default" on one line with typed char + previousToken = LexUtilities.findPreviousToken(ts, Arrays.asList(PHPTokenId.PHP_SWITCH)); + if (previousToken != null && previousToken.id() == PHPTokenId.PHP_SWITCH) { + Token<? extends PHPTokenId> firstCaseInSwitch = LexUtilities.findNextToken(ts, Arrays.asList(PHPTokenId.PHP_CASE)); + if (firstCaseInSwitch != null && firstCaseInSwitch.id() == PHPTokenId.PHP_CASE) { + int indentOfFirstCase = GsfUtilities.getLineIndent((Document) doc, ts.offset()); + GsfUtilities.setLineIndentation((Document) doc, offset, indentOfFirstCase); + } } } } else if (id == PHPTokenId.PHP_CURLY_CLOSE) { OffsetRange begin = LexUtilities.findBwd(doc, ts, PHPTokenId.PHP_CURLY_OPEN, '{', PHPTokenId.PHP_CURLY_CLOSE, '}'); if (begin != OffsetRange.NONE) { int beginOffset = begin.getStart(); - int indent = GsfUtilities.getLineIndent(doc, beginOffset); - previousAdjustmentIndent = GsfUtilities.getLineIndent(doc, offset); - GsfUtilities.setLineIndentation(doc, offset, indent); + int indent = GsfUtilities.getLineIndent((Document) doc, beginOffset); + previousAdjustmentIndent = GsfUtilities.getLineIndent((Document) doc, offset); + GsfUtilities.setLineIndentation((Document) doc, offset, indent); previousAdjustmentOffset = caret.getDot(); } } diff --git a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/typinghooks/PhpTypedTextInterceptorTest.java b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/typinghooks/PhpTypedTextInterceptorTest.java index 144a453e64..4f64215ea0 100644 --- a/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/typinghooks/PhpTypedTextInterceptorTest.java +++ b/php/php.editor/test/unit/src/org/netbeans/modules/php/editor/typinghooks/PhpTypedTextInterceptorTest.java @@ -662,6 +662,42 @@ public class PhpTypedTextInterceptorTest extends PhpTypinghooksTestBase { insertChar("'\"(a)\"'^", '[', "[\"(a)\"]^", "'\"(a)\"'"); } + public void testIssueGH5707_01() throws Exception { + String original = "" + + "switch ($variable) {\n" + + " case 1:\n" + + " break;\n" + + " case 2:\n" + + " break;\n" + + " ^\n" + + "}"; + String expected = "" + + "switch ($variable) {\n" + + " case 1:\n" + + " break;\n" + + " case 2:\n" + + " break;\n" + + " ^\n" + + "}"; + insertChar(original, ' ', expected); + } + + public void testIssueGH5707_02() throws Exception { + String original = "" + + "enum Enum1 {\n" + + " case A = 'A';\n" + + " case B = 'B';\n" + + " ^\n" + + "}"; + String expected = "" + + "enum Enum1 {\n" + + " case A = 'A';\n" + + " case B = 'B';\n" + + " ^\n" + + "}"; + insertChar(original, ' ', expected); + } + // Uncomment when CslTestBase.insertChar() will support ambiguous selection strings // // public void testIssue242358() throws Exception { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists