There is no need to check doc->real_path since the usage is NULL-safe,
and if it actually is empty or NULL it isn't a bug in the caller itself
anyway, and this could leak.
Fix the selection start position after uncommenting if it was inside
the comment marker; and fix the selection end position if it was in
the indentation or before or inside the comment marker.
Improved fix for #3576431.
The last line doesn't have EOL characters, so computing
(line_length() - eol_length()) is wrong on the last line.
Instead, use (line_end_pos() - line_start_pos()) as suggests
Scintilla's documentation.
Closes PR#124
If current position is not at selection start (e.g. bottom-up
selection), editor_get_filetype_at_current_pos() will start returning
improper result as soon as the first buffer change since the style at
the actual current position will have been invalidated and not yet
recomputed.
If the cursor was inside one of the comment's delimiters, the code used
to look for another delimiter, leading to removing previous comment's
start. Moreover, the code assumed the delimiter will always be found,
leading to improper deletions if a delimiter could not be found (either
because of the above problem or because the comment wasn't terminated).
Also, the code used document_find_text() which, if the searched text
cannot be found on the requested direction, either wraps or asks the
user whether to wrap. Wrapping is wrong if there is more than one
single comment in the file, and the dialog is confusing for the use
since she didn't ask for it.
So, rework the code for it to correctly find the delimiters, and not
to wrap search or ask the user. It is also simpler by reusing some
already existing code.
The implementation drops the non-selection code paths and simply makes
sure both caret and anchor are placed at the same position if there
was no selection. This avoids having two completely different code
paths for things that are very similar -- and alternative code paths
were buggy.
Closes#3576431.
When collapsing a fold range whose starting line is offscreen,
scroll the starting line to display at the top of the view.
Otherwise it can be confusing when the document scrolls down to hide
the folded lines.
For all languages, this change allows comments at the end of the
checked line, e.g.:
if 42: # magic number
print("I'm indented!")
For languages with braces, it also properly indent if there is code
on the same line as the opening brace, e.g.:
if (42) { printf("some code here...");
printf("...but I'm properly indented");
} else { /* comment! */
printf("normal block is fine too, of course");
}
Although this is uncommon (and quite ugly) it's valid and should be
handled properly.
Replacing spaces used for alignment with tabs would often break the
alignment as tab stop positions were not checked. It's also not
possible to distinguish between a true space and a single aligning
space, so we should ignore all spaces outside of indentation.