chdir one level down into the directory of the file located under the cursor or just above the screen
| 2804 | |
| 2805 | // chdir one level down into the directory of the file located under the cursor or just above the screen |
| 2806 | void Query::select() |
| 2807 | { |
| 2808 | if (!selected_file_.empty()) |
| 2809 | { |
| 2810 | Screen::alert(); |
| 2811 | return; |
| 2812 | } |
| 2813 | |
| 2814 | int ref = select_ >= 0 ? select_ : row_; |
| 2815 | |
| 2816 | // --tree: move down over non-filename lines to reach a filename |
| 2817 | if (flag_tree && (flag_files_with_matches || flag_count)) |
| 2818 | { |
| 2819 | while (ref + 1 < rows_ && (view_[ref].empty() || view_[ref].front() != '\0')) |
| 2820 | ++ref; |
| 2821 | } |
| 2822 | else |
| 2823 | { |
| 2824 | // move down to skip empty lines |
| 2825 | while (ref + 1 < rows_ && view_[ref].empty()) |
| 2826 | ++ref; |
| 2827 | } |
| 2828 | |
| 2829 | std::string pathname; |
| 2830 | bool found = false; |
| 2831 | |
| 2832 | // move up until a filename header is found |
| 2833 | while (ref >= 0 && !(found = find_filename(ref, pathname, false, true))) |
| 2834 | --ref; |
| 2835 | |
| 2836 | if (pathname.empty()) |
| 2837 | found = false; |
| 2838 | |
| 2839 | if (found) |
| 2840 | { |
| 2841 | // cannot view standard input |
| 2842 | if (flag_stdin && pathname == flag_label) |
| 2843 | { |
| 2844 | message("cannot chdir to standard input"); |
| 2845 | return; |
| 2846 | } |
| 2847 | |
| 2848 | if (globbing_) |
| 2849 | { |
| 2850 | globbing_ = false; |
| 2851 | |
| 2852 | memcpy(line_, temp_, sizeof(Line)); |
| 2853 | len_ = line_len(); |
| 2854 | move(len_); |
| 2855 | |
| 2856 | set_prompt(); |
| 2857 | } |
| 2858 | |
| 2859 | if (history_.empty()) |
| 2860 | files_.swap(Static::arg_files); |
| 2861 | |
| 2862 | history_.emplace(); |
| 2863 | history_.top().save(); |