MCPcopy Create free account
hub / github.com/Genivia/ugrep / preview

Method preview

src/query.cpp:2686–2803  ·  view source on GitHub ↗

preview the file located under the cursor when the screen is split into multiple windows

Source from the content-addressed store, hash-verified

2684
2685// preview the file located under the cursor when the screen is split into multiple windows
2686void Query::preview()
2687{
2688 if (!flag_split || error_ != -1)
2689 return;
2690
2691 bool found = false;
2692 std::string filename;
2693 std::string partname;
2694
2695 if (rows_ > 0)
2696 {
2697 int ref = row_;
2698
2699 // --tree with -c or -l: move down over non-filename lines to reach a filename
2700 if (flag_tree && (flag_files_with_matches || flag_count))
2701 while (ref + 1 < rows_ && (view_[ref].empty() || view_[ref].front() != '\0'))
2702 ++ref;
2703
2704 // find a filename upwards, unless we're at an empty line
2705 if (!view_[ref].empty())
2706 while (ref >= 0 && !(found = find_filename(ref, filename, false, true, &partname)))
2707 --ref;
2708
2709 // only a partname was present, no filename
2710 if (filename.empty())
2711 found = false;
2712
2713 if (found && filename.back() == PATHSEPCHR)
2714 {
2715 found = false;
2716 }
2717 else if (!found && Static::arg_files.size() == 1)
2718 {
2719 // if not found an only one FILE argument was provided then preview FILE
2720 filename = Static::arg_files.front();
2721 found = true;
2722 }
2723
2724 // cannot preview standard input
2725 if (found && flag_stdin && filename.compare(flag_label) == 0)
2726 found = false;
2727 }
2728
2729 // no problems to report
2730 const char *problem = NULL;
2731
2732 if (found)
2733 {
2734 // get line number if any, zero otherwise
2735 size_t from_lineno =
2736 flag_line_number &&
2737 !flag_files_with_matches &&
2738 !flag_count && !flag_hex &&
2739 !flag_with_hex ? get_line_number() : 0;
2740
2741 // has the filename or partname or line number changed?
2742 if (from_lineno == 0 ||
2743 from_lineno != prevfrom_ ||

Callers

nothing calls this directly

Calls 6

ugrep_find_text_previewFunction · 0.85
swapMethod · 0.80
emptyMethod · 0.45
backMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected