From 016569905e64e487d847b18f29a8a838baaa15de Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Wed, 23 Jun 2021 00:19:42 +0200 Subject: [PATCH] commandline: move handling of cursor option No behavior change intended. Will use the "buffer_part" computation in the next commit. --- src/builtin_commandline.cpp | 38 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/builtin_commandline.cpp b/src/builtin_commandline.cpp index 888026bef..91225f248 100644 --- a/src/builtin_commandline.cpp +++ b/src/builtin_commandline.cpp @@ -372,25 +372,6 @@ maybe_t builtin_commandline(parser_t &parser, io_streams_t &streams, const buffer_part = STRING_MODE; } - if (cursor_mode) { - if (argc - w.woptind) { - long new_pos = fish_wcstol(argv[w.woptind]); - if (errno) { - streams.err.append_format(BUILTIN_ERR_NOT_NUMBER, cmd, argv[w.woptind]); - builtin_print_error_trailer(parser, streams.err, cmd); - } - - current_buffer = reader_get_buffer(); - new_pos = - std::max(0L, std::min(new_pos, static_cast(std::wcslen(current_buffer)))); - reader_set_buffer(current_buffer, static_cast(new_pos)); - } else { - streams.out.append_format(L"%lu\n", - static_cast(reader_get_cursor_pos())); - } - return STATUS_CMD_OK; - } - if (line_mode) { size_t pos = reader_get_cursor_pos(); const wchar_t *buff = reader_get_buffer(); @@ -431,6 +412,25 @@ maybe_t builtin_commandline(parser_t &parser, io_streams_t &streams, const } } + if (cursor_mode) { + if (argc - w.woptind) { + long new_pos = fish_wcstol(argv[w.woptind]); + if (errno) { + streams.err.append_format(BUILTIN_ERR_NOT_NUMBER, cmd, argv[w.woptind]); + builtin_print_error_trailer(parser, streams.err, cmd); + } + + current_buffer = reader_get_buffer(); + new_pos = + std::max(0L, std::min(new_pos, static_cast(std::wcslen(current_buffer)))); + reader_set_buffer(current_buffer, static_cast(new_pos)); + } else { + streams.out.append_format(L"%lu\n", + static_cast(reader_get_cursor_pos())); + } + return STATUS_CMD_OK; + } + int arg_count = argc - w.woptind; if (arg_count == 0) { write_part(begin, end, cut_at_cursor, tokenize, current_buffer, current_cursor_pos,