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

If file is already open, switch to it instead of opening it again #27

Open
DanielPower opened this issue Feb 5, 2018 · 6 comments
Open

Comments

@DanielPower
Copy link

If a file is already open, selecting it from the tree should switch focus to the pane that file is in, rather than opening it again in a new pane.

@sum01
Copy link
Collaborator

sum01 commented Feb 5, 2018

Not actually sure how to get current open files. I know it's contained in the tabs variable, but that's about it.

@sum01
Copy link
Collaborator

sum01 commented Mar 4, 2018

This should be possible now with zyedidia/micro@cb45481

I'll look into it, but I encourage PR's as well :)

@DanielPower
Copy link
Author

I'd be interested in implementing this, but don't have time this week. If you get to it before me, that's great. If not, I'll post here when I start working on it so we don't duplicate our efforts.

@sum01
Copy link
Collaborator

sum01 commented Mar 4, 2018

Here's a function to get the opened files indicies

-- Check if the target abspath is already opened
local function find_open_file(tar_abspath)
	-- What we return
	local results = {
		["tabs_i"] = nil,
		["views_i"] = nil
	}
	-- Go through each tab
	for i = 0, curTab do
		-- Go through each view in the tab
		-- Note that Views[0] is NEVER VALID
		for x = 1, #tabs[i + 1].Views do
			-- Seems to take one-based on its arrays, even though Go is zero-based
			if tar_abspath == tabs[i + 1].Views[x].Buf.AbsPath then
				results.tab_i = i + 1
				results.view_i = x
				return results
			end
		end
	end
	return results
end

but I'm kind of blanking on how to set the cursor to it.

@sum01
Copy link
Collaborator

sum01 commented Mar 25, 2018

Note that until zyedidia/micro#1070 is fixed, an open file in a different tab will not be able to be detected with the above code.

Once it's fixed, the only thing stopping this issue being closed is how to move the cursor to the target view. That might already be possible, but I haven't really looked for it yet.

@sum01
Copy link
Collaborator

sum01 commented Aug 15, 2018

zyedidia/micro#1154 may have made this possible now, although I haven't checked. Ref zyedidia/micro#1070 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants