MCPcopy Create free account
hub / github.com/Predelnik/DSpellCheck / char_position_from_point

Method char_position_from_point

test/MockEditorInterface.cpp:463–484  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

461}
462
463TextPosition MockEditorInterface::char_position_from_point(
464 const POINT &pnt) const {
465 auto doc = active_document();
466 if (!doc)
467 return -1;
468 auto line_end_cnt = static_cast<TextPosition>((pnt.y + m_editor_rect.top) / char_height);
469 TextPosition pos = 0;
470 for (int i = 0; i < line_end_cnt; ++i) {
471 auto next_pos = doc->cur.data.find_first_of("\r\n", pos);
472 if (next_pos == std::string::npos)
473 break;
474 pos = next_pos + 1;
475 }
476 TextPosition next_pos = doc->cur.data.find_first_of("\r\n", pos);
477 if (next_pos == std::string::npos)
478 next_pos = doc->cur.data.length();
479 --next_pos;
480 pos += static_cast<TextPosition>((pnt.x + m_editor_rect.left) / char_width);
481 if (pos > next_pos)
482 pos = next_pos;
483 return pos;
484}
485
486RECT MockEditorInterface::editor_rect() const {
487 return m_editor_rect;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected