MCPcopy Create free account
hub / github.com/OpenOrienteering/mapper / inputMethodEvent

Method inputMethodEvent

src/tools/text_object_editor_helper.cpp:407–504  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

405
406
407bool TextObjectEditorHelper::inputMethodEvent(QInputMethodEvent* event)
408{
409#ifdef DEBUG_INPUT_METHOD_SUPPORT
410 QString a;
411 const auto att = event->attributes();
412 for (const auto& attribute : att)
413 {
414 a += QString::fromLatin1("\n att %1: %2,%3").arg(attribute.type).arg(attribute.start).arg(attribute.length);
415 }
416 qDebug("\n>>> ime \"%s\" @ %d,%d [%s]%s",
417 qPrintable(event->commitString()), event->replacementStart(), event->replacementLength(),
418 qPrintable(event->preeditString()),
419 qPrintable(a));
420#endif
421
422 // This method updates the editor to match the input method,
423 // so it must not modify the input method.
424 TextObjectEditorHelper::BatchEdit transaction(this, NoInputMethodAction);
425
426 auto position = cursor_position;
427 auto length = anchor_position - cursor_position;
428 auto old_pristine_text = pristine_text;
429
430 // Remove the current non-empty selection
431 // if we are not only moving the selection.
432 if (length != 0)
433 {
434 if (event->replacementLength() > 0
435 || !event->commitString().isEmpty()
436 || !event->preeditString().isEmpty())
437 {
438 if (length < 0)
439 {
440 // Swap for QString operations
441 position = anchor_position;
442 length = -length;
443 }
444 pristine_text.remove(position, length);
445 }
446 }
447
448 // Insert the commit string for the given replacement length
449 position += event->replacementStart();
450 length = event->replacementLength();
451 if (position < 0)
452 {
453 length = qMax(0, length + position);
454 position = 0;
455 }
456 pristine_text.replace(position, length, event->commitString());
457 position += event->commitString().length();
458 length = 0;
459
460 if (old_pristine_text != pristine_text)
461 {
462 dirty = true;
463 }
464

Callers

nothing calls this directly

Calls 4

removeMethod · 0.80
isEmptyMethod · 0.45
lengthMethod · 0.45
acceptMethod · 0.45

Tested by

no test coverage detected