Use emscripten rich text clipboard method in native version as well to fix character encoding issues
This commit is contained in:
parent
f97029552f
commit
f5d496bc45
3 changed files with 12 additions and 31 deletions
|
|
@ -33,7 +33,7 @@ EM_JS_INLINE(void, paste_js, (paste_handler callback, void *callback_data), {
|
||||||
/// Paste handler callback signature is:
|
/// Paste handler callback signature is:
|
||||||
/// void my_handler(std::string const &paste_data, void *callback_data = nullptr);
|
/// void my_handler(std::string const &paste_data, void *callback_data = nullptr);
|
||||||
document.addEventListener('paste', (event) => {
|
document.addEventListener('paste', (event) => {
|
||||||
Module["ccall"]('emscripten_browser_clipboard_detail_paste_return', 'number', ['string', 'number', 'number'], [event.clipboardData.getData('text/plain'), callback, callback_data]);
|
Module["ccall"]('emscripten_browser_clipboard_detail_paste_return', 'number', ['string', 'number', 'number'], [event.clipboardData.getData('text/plain;charset=UTF-8'), callback, callback_data]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -147,20 +147,9 @@ void InputManager::set_clipboard_str(std::string_view s) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string InputManager::get_infpnt_richtext_mimetype() {
|
|
||||||
return "web text/infpnt";
|
|
||||||
}
|
|
||||||
|
|
||||||
void InputManager::set_clipboard_plain_and_richtext_pair(const std::pair<std::string, RichText::TextData>& plainAndRichtextPair) {
|
void InputManager::set_clipboard_plain_and_richtext_pair(const std::pair<std::string, RichText::TextData>& plainAndRichtextPair) {
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
set_clipboard_str(plainAndRichtextPair.first);
|
set_clipboard_str(plainAndRichtextPair.first);
|
||||||
lastCopiedRichText = plainAndRichtextPair.second;
|
lastCopiedRichText = plainAndRichtextPair.second;
|
||||||
#else
|
|
||||||
std::unordered_map<std::string, std::string> clipboardData;
|
|
||||||
clipboardData["text/plain"] = plainAndRichtextPair.first;
|
|
||||||
clipboardData[get_infpnt_richtext_mimetype()] = plainAndRichtextPair.second.get_serialized();
|
|
||||||
set_clipboard_data(clipboardData);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputManager::set_clipboard_data(const std::unordered_map<std::string, std::string>& newClipboardData) {
|
void InputManager::set_clipboard_data(const std::unordered_map<std::string, std::string>& newClipboardData) {
|
||||||
|
|
@ -176,6 +165,7 @@ void InputManager::set_clipboard_data(const std::unordered_map<std::string, std:
|
||||||
std::unordered_map<std::string, std::string>& clipboardData = *static_cast<std::unordered_map<std::string, std::string>*>(userdata);
|
std::unordered_map<std::string, std::string>& clipboardData = *static_cast<std::unordered_map<std::string, std::string>*>(userdata);
|
||||||
std::string mimeTypeStr(mime_type);
|
std::string mimeTypeStr(mime_type);
|
||||||
auto it = clipboardData.find(mimeTypeStr);
|
auto it = clipboardData.find(mimeTypeStr);
|
||||||
|
std::cout << "requesting: " << mime_type << std::endl;
|
||||||
if(it == clipboardData.end())
|
if(it == clipboardData.end())
|
||||||
return static_cast<const void*>(nullptr);
|
return static_cast<const void*>(nullptr);
|
||||||
*size = it->second.length();
|
*size = it->second.length();
|
||||||
|
|
@ -387,7 +377,6 @@ void InputManager::backend_key_down_update(const SDL_KeyboardEvent& e) {
|
||||||
|
|
||||||
void InputManager::process_text_paste() {
|
void InputManager::process_text_paste() {
|
||||||
if(text.textBox) {
|
if(text.textBox) {
|
||||||
#ifdef __EMSCRIPTEN__
|
|
||||||
// Workaround for not being able to copy richtext to system clipboard, this should at least work within the application itself
|
// Workaround for not being able to copy richtext to system clipboard, this should at least work within the application itself
|
||||||
std::string plainClipboardStr = get_clipboard_str();
|
std::string plainClipboardStr = get_clipboard_str();
|
||||||
if(lastCopiedRichText.has_value()) {
|
if(lastCopiedRichText.has_value()) {
|
||||||
|
|
@ -398,13 +387,6 @@ void InputManager::process_text_paste() {
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
text.textBox->process_text_input(*text.cursor, plainClipboardStr, text.modMap);
|
text.textBox->process_text_input(*text.cursor, plainClipboardStr, text.modMap);
|
||||||
#else
|
|
||||||
std::string richTextClipboard = get_clipboard_data_for_mimetype(get_infpnt_richtext_mimetype());
|
|
||||||
if(!richTextClipboard.empty())
|
|
||||||
text.textBox->process_rich_text_input(*text.cursor, RichText::TextData::deserialize_string(richTextClipboard));
|
|
||||||
else
|
|
||||||
text.textBox->process_text_input(*text.cursor, get_clipboard_data_for_mimetype("text/plain"), text.modMap);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -203,16 +203,15 @@ struct InputManager {
|
||||||
void set_clipboard_data(const std::unordered_map<std::string, std::string>& newClipboardData);
|
void set_clipboard_data(const std::unordered_map<std::string, std::string>& newClipboardData);
|
||||||
void process_text_paste();
|
void process_text_paste();
|
||||||
|
|
||||||
static std::string get_infpnt_richtext_mimetype();
|
|
||||||
|
|
||||||
std::unordered_map<std::string, std::string> clipboardData;
|
std::unordered_map<std::string, std::string> clipboardData;
|
||||||
|
|
||||||
#ifdef __EMSCRIPTEN__
|
#ifdef __EMSCRIPTEN__
|
||||||
bool clipboardPasteEventHappened = false;
|
bool clipboardPasteEventHappened = false;
|
||||||
std::unordered_map<std::string, std::string> clipboardPasteEventData;
|
std::unordered_map<std::string, std::string> clipboardPasteEventData;
|
||||||
std::optional<RichText::TextData> lastCopiedRichText;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
std::optional<RichText::TextData> lastCopiedRichText;
|
||||||
|
|
||||||
std::string key_assignment_to_str(const Vector2ui32& k);
|
std::string key_assignment_to_str(const Vector2ui32& k);
|
||||||
Vector2ui32 key_assignment_from_str(const std::string& s);
|
Vector2ui32 key_assignment_from_str(const std::string& s);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue