Normalize loaded content for text/plain;charset=utf-8 mime type (#9)

Normalize \r\n and \r into \n
This commit is contained in:
Kirill Chibisov 2019-10-30 03:03:25 +03:00 committed by trimental
parent 3f727066e5
commit e10bbfac70
2 changed files with 17 additions and 0 deletions

View file

@ -2,6 +2,8 @@
## Unreleased
- Perform loaded data normalization for text/plain;charset=utf-8 mime type
## 0.3.5 -- 2019-09-3
- Fix primary selection storing, when releasing button outside of the surface

View file

@ -309,6 +309,9 @@ fn clipboard_thread(
contents
})
});
// Normalization should happen only on `text/plain;charset=utf-8`, in case we
// add other mime types consult gtk for normalization.
let contents = normilize_to_lf(contents);
load_send.send(contents).unwrap();
}
// Store text in the clipboard
@ -400,6 +403,9 @@ fn clipboard_thread(
} else {
String::new()
};
// Normalization should happen only on `text/plain;charset=utf-8`, in case we
// add other mime types consult gtk for normalization.
let contents = normilize_to_lf(contents);
load_send.send(contents).unwrap();
}
// Store text in the primary clipboard
@ -719,3 +725,12 @@ fn implement_seat(
})
.unwrap();
}
// Normalize \r and \r\n into \n.
//
// Gtk does this for text/plain;charset=utf-8, so following them here, otherwise there is
// a chance of getting extra new lines on load, since they're converting \r and \n into
// \r\n on every store.
fn normilize_to_lf(text: String) -> String {
text.replace("\r\n", "\n").replace("\r", "\n")
}