Module: RuVim::Git::Status::HandlerMethods
- Included in:
- Handler
- Defined in:
- lib/ruvim/git/status.rb
Overview
Command handler methods
Instance Method Summary collapse
Instance Method Details
#git_status(ctx) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ruvim/git/status.rb', line 44 def git_status(ctx, **) file_path = git_resolve_path(ctx) unless file_path ctx.editor.echo_error("No file or directory to resolve git repo") return end lines, root, err = Status.run(file_path) unless lines ctx.editor.echo_error("git status: #{err}") return end buf = ctx.editor.add_virtual_buffer( kind: :git_status, name: "[Git Status]", lines: lines, readonly: true, modifiable: false ) buf.["git_repo_root"] = root ctx.editor.switch_to_buffer(buf.id) bind_git_buffer_keys(ctx.editor, buf.id) ctx.editor.echo("[Git Status]") end |
#git_status_open_file(ctx) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/ruvim/git/status.rb', line 70 def git_status_open_file(ctx, **) buf = ctx.buffer unless buf.kind == :git_status ctx.editor.echo_error("Not a git status buffer") return end line = buf.line_at(ctx.window.cursor_y) filename = Status.parse_filename(line) unless filename ctx.editor.echo_error("No file on this line") return end root = buf.["git_repo_root"] full_path = File.join(root, filename) unless File.exist?(full_path) ctx.editor.echo_error("File not found: #{filename}") return end existing = ctx.editor.buffers.values.find { |b| b.path == full_path } if existing ctx.editor.switch_to_buffer(existing.id) else new_buf = ctx.editor.add_buffer_from_file(full_path) ctx.editor.switch_to_buffer(new_buf.id) end end |