MCPcopy Create free account
hub / github.com/cataclysmbn/Cataclysm-BN / query_string

Method query_string

src/string_editor_window.cpp:543–749  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

541}
542
543std::pair<bool, std::string> string_editor_window::query_string()
544{
545 if( !ctxt ) {
546 create_context();
547 }
548
549 utf8_wrapper edit( ctxt->get_edittext() );
550 if( _position == -1 ) {
551 _position = _utext.length();
552 }
553
554 // fold the text
555 bool refold = true;
556 // calculate the cursor position
557 bool reposition = true;
558
559 ui_adaptor ui;
560 ui.on_screen_resize( [&]( ui_adaptor & ui ) {
561 _win = _create_window();
562 _max.x = getmaxx( _win );
563 _max.y = getmaxy( _win );
564 _cursor_desired_x = -1;
565 refold = true;
566 ui.position_from_window( _win );
567 } );
568 ui.mark_resize();
569 ui.on_redraw( [&]( ui_adaptor & ui ) {
570 if( refold ) {
571 utf8_wrapper text = _utext;
572 if( !edit.empty() ) {
573 text.insert( _position, edit );
574 }
575 if( _show_line_numbers ) {
576 _line_number_width = get_line_number_width( text.str(), _line_number_min_width );
577 } else {
578 _line_number_width = 0;
579 }
580 const auto gutter_width = _show_line_numbers ? _line_number_width + 1 : 0;
581 const auto fold_width = std::max( 1, _max.x - 2 - gutter_width );
582 _folded = std::make_unique<folded_text>( text.str(), fold_width );
583 refold = false;
584 reposition = true;
585 }
586 if( reposition ) {
587 _cursor_display = get_line_and_position( _position, _cursor_desired_x == 0 );
588 if( _cursor_desired_x < 0 ) {
589 _cursor_desired_x = _cursor_display.x;
590 }
591 if( edit.empty() ) {
592 _ime_preview_range.reset();
593 } else {
594 _ime_preview_range = std::make_unique<ime_preview_range>( ime_preview_range{
595 _position, _position + static_cast<int>( edit.size() ),
596 _cursor_display, get_line_and_position( _position + edit.size() - 1, true )
597 } );
598 }
599 reposition = false;
600 }

Callers 15

query_durationFunction · 0.80
showMethod · 0.80
show_lua_console_implFunction · 0.80
done_vehicleMethod · 0.80
keyMethod · 0.80
edit_page_uiMethod · 0.80
useMethod · 0.80
rename_petMethod · 0.80
edit_jsonFunction · 0.80

Calls 15

get_line_number_widthFunction · 0.85
maxFunction · 0.85
redrawFunction · 0.85
is_linebreakFunction · 0.85
utf32_to_utf8Function · 0.85
stringClass · 0.85
get_edittextMethod · 0.80
lengthMethod · 0.80
on_screen_resizeMethod · 0.80
position_from_windowMethod · 0.80
mark_resizeMethod · 0.80

Tested by

no test coverage detected