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

fix: don't add additional asterisks in c style docs #5323

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/mode/behaviour/behaviour_test.js
Expand Up @@ -7,7 +7,7 @@

require("../../multi_select");
var assert = require("../../test/assertions");
var Range = require("../../range").Range;

Check warning on line 10 in src/mode/behaviour/behaviour_test.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'Range' is assigned a value but never used
var Editor = require("../../editor").Editor;
var UndoManager = require("../../undomanager").UndoManager;
var EditSession = require("../../edit_session").EditSession;
Expand All @@ -25,7 +25,7 @@
editor.commands.exec(name, editor, args);
} while(times --> 1);
};
var testRanges = function(str) {

Check warning on line 28 in src/mode/behaviour/behaviour_test.js

View workflow job for this annotation

GitHub Actions / build (16.x)

'testRanges' is assigned a value but never used
assert.equal(editor.selection.getAllRanges() + "", str + "");
};

Expand Down Expand Up @@ -435,6 +435,15 @@
editor.setValue(" /**", 1);
exec("insertstring", 1, "\n");
assert.equal(editor.getValue(), " /**\n * \n */");

// Test case 4: Pressing enter before an asterisk (*)
editor.setValue("/**\n * \n */");
editor.gotoLine(1, 0);
exec("insertstring", 1, "\n");
assert.equal(editor.getValue(), "\n/**\n * \n */");
editor.gotoLine(3, 1);
exec("insertstring", 1, "\n");
assert.equal(editor.getValue(), "\n/**\n \n * \n */");
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/mode/behaviour/cstyle.js
Expand Up @@ -311,7 +311,8 @@ var CstyleBehaviour = function(options) {
var line = session.doc.getLine(cursor.row);
var nextLine = session.doc.getLine(cursor.row + 1);
var indent = this.$getIndent(line);
if (/\s*\*/.test(nextLine)) {
const beforeCursor = line.substring(0, cursor.column);
if (/\s*\*/.test(nextLine) && /\*/.test(beforeCursor)) {
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this match a * b /**comment*/ with cursor before the comment ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I don't think so because we still check if there is an * in next line, so I guess it would match:

a * b /**<cursor>comment*/
*

Which would be turned into

a * b /**
* <cursor>comment*/
*

I think, but let me double check this. Nice test example!!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah so actually nothing cool happens because state is not "doc-start", so it just goes into new line.

Copy link
Member

Choose a reason for hiding this comment

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

sorry, my bad for including */ in the end of the example. In default js example of this pull request https://raw.githack.com/ajaxorg/ace/d52d9b32e5eb23a2a1981bf2b10344ede05b2214/kitchen-sink.html, if i press enter at the start of the file, the bug is indeed fixed, but if i type * at the start and only then press enter the comment indentation is applied.
We either need to test for a more specific pattern, or compute the state in the middle of line like outdent does.

Copy link
Contributor

Choose a reason for hiding this comment

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

@marinsokol5 I could reproduce the issue highlighted by @nightwing, could you please take a look into it and update your PR to address it?

if (/^\s*\*/.test(line)) {
return {
text: text + indent + "* ",
Expand Down