Skip to content
Open
Show file tree
Hide file tree
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
135 changes: 135 additions & 0 deletions DUAL_PANE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# GitGraph Dual-Pane Mode

GitGraph dual-pane mode provides a split-screen interface for viewing Git commit graphs with synchronized scrolling. The dual-pane mode opens in a new tab to avoid conflicts with existing buffers.

## Features

- **Split-screen layout**: Graph visualization in left pane, commit details in right pane
- **Synchronized vertical scrolling**: Both panes scroll together vertically
- **Independent horizontal scrolling**: Each pane can scroll horizontally independently
- **Window switching**: Use `<Tab>` to switch between panes
- **Scroll sync toggle**: Use `<leader>gs` to enable/disable scroll synchronization

## Usage

### Command

```vim
:GitGraphDual [args]
```

### Programmatic Usage

```lua
-- Basic usage
require('gitgraph').draw_dual({}, { all = true, max_count = 5000 })

-- With options
require('gitgraph').draw_dual({}, {
all = true,
max_count = 1000,
revision_range = "HEAD~10..HEAD"
})
```

### Plugin Configuration

Add this to your plugin configuration to automatically register the `GitGraphDual` command:

```lua
return {
{
'isakbm/gitgraph.nvim',
opts = {
symbols = {
merge_commit = 'M',
commit = '*',
},
format = {
timestamp = '%H:%M:%S %d-%m-%Y',
fields = { 'hash', 'timestamp', 'author', 'branch_name', 'tag' },
},
hooks = {
on_select_commit = function(commit)
print('selected commit:', commit.hash)
end,
on_select_range_commit = function(from, to)
print('selected range:', from.hash, to.hash)
end,
},
},
keys = {
{
"<leader>gph",
function()
require('gitgraph').draw({}, { all = true, max_count = 5000 })
end,
desc = "GitGraph - Single Pane",
},
{
"<leader>gpd",
function()
require('gitgraph').draw_dual({}, { all = true, max_count = 5000 })
end,
desc = "GitGraph - Dual Pane",
},
},
}
}
```

## Keybindings

| Key | Action |
|-----|--------|
| `<CR>` | Select commit under cursor |
| `<Tab>` | Switch between graph and text panes |
| `<leader>gs` | Toggle scroll synchronization |
| `j/k` | Navigate up/down (synchronized) |
| `h/l` | Horizontal scroll (independent per pane) |
| `v + <CR>` | Select commit range (visual mode) |
| `q` | Close dual-pane tab |

## Pane Layout

```
┌─────────────────┬─────────────────────────────────────┐
│ │ │
│ Git Graph │ Commit Details │
│ (Visual) │ (Hash, Author, Date, Message) │
│ │ │
│ * │ abc1234 12:34:56 John Doe │
│ │ │ feat: add new feature │
│ * │ │
│ │ │ def5678 11:20:30 Jane Smith │
│ * │ fix: resolve bug in parser │
│ │ │
└─────────────────┴─────────────────────────────────────┘
```

## Arguments

The dual-pane mode supports the same arguments as the regular GitGraph:

- `all`: Show all branches
- `max_count=N`: Limit number of commits
- `revision_range`: Specify commit range (e.g., "HEAD~10..HEAD")

## Customization

All standard GitGraph configuration options apply to dual-pane mode:

- `symbols`: Customize graph symbols
- `format`: Configure timestamp and field display
- `hooks`: Set up commit selection handlers
- `highlights`: Customize colors and highlighting

## Technical Notes

- Requires Neovim 0.8+
- Must be run from within a Git repository
- Opens in a new tab to avoid buffer name conflicts
- Creates two synchronized buffers with independent horizontal scrolling
- Scroll synchronization can be toggled at runtime
- Uses unique buffer names with timestamps to prevent conflicts
- Press `q` to close the dual-pane tab
128 changes: 128 additions & 0 deletions DUAL_PANE_CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# GitGraph Dual-Pane Implementation - Changes Summary

## Overview

This document summarizes the implementation of dual-pane functionality for the GitGraph.nvim plugin. The dual-pane mode provides a split-screen interface with synchronized vertical scrolling and independent horizontal scrolling.

## Files Added

### Core Implementation
- `lua/gitgraph/draw_dual.lua` - Main dual-pane rendering logic
- `plugin/gitgraph.lua` - Auto-registration of GitGraphDual command
- `DUAL_PANE.md` - Comprehensive documentation for dual-pane mode

## Files Modified

### `lua/gitgraph.lua`
- Added `draw_dual()` function for dual-pane mode
- Maintained backward compatibility with existing API

### `lua/gitgraph/core.lua`
- Added `gitgraph_dual()` function
- Added `_gitgraph_dual()` internal function
- Added `graph_to_lines_dual()` function to separate graph and text data
- Enhanced data processing to support dual-pane rendering

### `README.md`
- Added dual-pane mode documentation
- Updated feature list
- Added usage examples and keybindings

## Key Features Implemented

### 1. Dual-Pane Layout
- **Left pane**: Visual git graph representation
- **Right pane**: Commit details (hash, timestamp, author, message, branches, tags)
- Automatic vertical split creation

### 2. Synchronized Scrolling
- Vertical scrolling synchronized between panes
- Independent horizontal scrolling per pane
- Toggle synchronization with `<leader>gs`

### 3. Window Management
- Switch between panes with `<Tab>`
- Proper window and buffer handling
- Automatic cleanup on buffer deletion

### 4. Enhanced Navigation
- All original keybindings preserved
- Additional dual-pane specific keybindings
- Visual mode support for commit range selection

## Technical Implementation Details

### Data Separation
The `graph_to_lines_dual()` function separates the original combined output into:
- `graph_lines[]` - Pure graph visualization (symbols only)
- `text_lines[]` - Commit information (hash, author, date, message, etc.)
- Separate highlight arrays for each pane

### Window Synchronization
- Uses Neovim's autocmd system for cursor movement detection
- Maintains window validity checks
- Prevents recursive synchronization with `updating_scroll` flag

### Error Handling
- Safe API calls with pcall where appropriate
- Graceful fallbacks for invalid data
- Proper validation of window and buffer handles

## Usage Integration

### Command Registration
The plugin automatically registers the `GitGraphDual` command when loaded, making it available immediately after plugin setup.

### API Compatibility
```lua
-- Original single-pane mode (unchanged)
require('gitgraph').draw({}, { all = true, max_count = 5000 })

-- New dual-pane mode
require('gitgraph').draw_dual({}, { all = true, max_count = 5000 })
```

### Plugin Configuration
Works seamlessly with existing plugin configurations. Users can add dual-pane keybindings alongside existing ones:

```lua
keys = {
-- Original single-pane
{ "<leader>gph", function() require('gitgraph').draw({}, { all = true, max_count = 5000 }) end },
-- New dual-pane
{ "<leader>gpd", function() require('gitgraph').draw_dual({}, { all = true, max_count = 5000 }) end },
}
```

## Keybindings

| Key | Action |
|-----|--------|
| `<CR>` | Select commit under cursor |
| `<Tab>` | Switch between graph and text panes |
| `<leader>gs` | Toggle scroll synchronization |
| `j/k` | Navigate up/down (synchronized) |
| `h/l` | Horizontal scroll (independent per pane) |
| `v + <CR>` | Select commit range (visual mode) |

## Benefits

1. **Enhanced Readability**: Separate panes make it easier to read both graph structure and commit details
2. **Better Space Utilization**: Graph symbols don't compete with text for horizontal space
3. **Flexible Navigation**: Independent horizontal scrolling allows focusing on either graph or details
4. **Preserved Functionality**: All original features remain available
5. **Easy Adoption**: Minimal configuration required, works with existing setups

## Backward Compatibility

- All existing functionality preserved
- Original `draw()` function unchanged
- Existing configurations continue to work
- No breaking changes to the API

## Performance Considerations

- Minimal overhead compared to single-pane mode
- Same data processing with additional separation step
- Efficient buffer and window management
- No impact on original functionality performance
Loading