Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix finding the start and end of the current query. #239

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions lua/rest-nvim/request/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ local function start_request(bufnr, linenumber)
local oldlinenumber = linenumber
utils.move_cursor(bufnr, linenumber)

local res = vim.fn.search("^GET\\|^POST\\|^PUT\\|^PATCH\\|^DELETE", "cn")
local res = vim.fn.search("^GET\\|^POST\\|^PUT\\|^PATCH\\|^DELETE", "bcnW")
-- restore cursor position
utils.move_cursor(bufnr, oldlinenumber)

Expand All @@ -206,20 +206,19 @@ end
local function end_request(bufnr, linenumber)
-- store old cursor position
local oldlinenumber = linenumber
local last_line = vim.fn.line("$")

-- start searching for next request from the next line
-- as the current line does contain the current, not the next request
if linenumber < vim.fn.line("$") then
if linenumber < last_line then
linenumber = linenumber + 1
end
utils.move_cursor(bufnr, linenumber)

local next =
vim.fn.search("^GET\\|^POST\\|^PUT\\|^PATCH\\|^DELETE\\|^###\\", "cn", vim.fn.line("$"))
local next = vim.fn.search("^GET\\|^POST\\|^PUT\\|^PATCH\\|^DELETE\\|^###\\", "cnW")

-- restore cursor position
utils.move_cursor(bufnr, oldlinenumber)
local last_line = vim.fn.line("$")

if next == 0 or (oldlinenumber == last_line) then
return last_line
Expand Down
Loading