[gnome-builder] buffer: ignore adding trailing \n when last char is \n
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] buffer: ignore adding trailing \n when last char is \n
- Date: Sat, 17 Feb 2018 21:54:37 +0000 (UTC)
commit d2f824c05629e72a16c98c17a6fc1b353a1d154b
Author: Christian Hergert <chergert redhat com>
Date: Sat Feb 17 13:54:15 2018 -0800
buffer: ignore adding trailing \n when last char is \n
If we need a trailing newline, and the trailing newline is already there,
the don't bother adding a new one.
This improves a situation where Builder thinks there is a new-line
added at the end of a file that is unmodified.
src/libide/buffers/ide-buffer.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/buffers/ide-buffer.c b/src/libide/buffers/ide-buffer.c
index fee1d6cd3..20eb43b6b 100644
--- a/src/libide/buffers/ide-buffer.c
+++ b/src/libide/buffers/ide-buffer.c
@@ -2268,7 +2268,8 @@ ide_buffer_get_content (IdeBuffer *self)
* The unsaved files will restore to a buffer, for which \n is acceptable.
*/
len = strlen (text);
- if (gtk_source_buffer_get_implicit_trailing_newline (GTK_SOURCE_BUFFER (self)))
+ if (gtk_source_buffer_get_implicit_trailing_newline (GTK_SOURCE_BUFFER (self)) &&
+ (len == 0 || text[len - 1] != '\n'))
{
if (!ide_buffer_can_do_newline_hack (self, len))
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]