mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
multigrid: do all adjustment in screen.c
Adjustment will get more complex with floats, tabgrid etc, so make it into a function.
This commit is contained in:
@@ -4256,20 +4256,15 @@ win_line (
|
|||||||
&& filler_todo <= 0 // Not drawing diff filler lines.
|
&& filler_todo <= 0 // Not drawing diff filler lines.
|
||||||
&& lcs_eol_one != -1 // Haven't printed the lcs_eol character.
|
&& lcs_eol_one != -1 // Haven't printed the lcs_eol character.
|
||||||
&& row != endrow - 1 // Not the last line being displayed.
|
&& row != endrow - 1 // Not the last line being displayed.
|
||||||
&& grid->Columns == Columns // Window spans the width of the screen.
|
&& (grid->Columns == Columns // Window spans the width of the screen,
|
||||||
|
|| ui_is_external(kUIMultigrid)) // or has dedicated grid.
|
||||||
&& !wp->w_p_rl; // Not right-to-left.
|
&& !wp->w_p_rl; // Not right-to-left.
|
||||||
grid_put_linebuf(grid, row, 0, col - boguscols, grid->Columns, wp->w_p_rl,
|
grid_put_linebuf(grid, row, 0, col - boguscols, grid->Columns, wp->w_p_rl,
|
||||||
wp, wp->w_hl_attr_normal, wrap);
|
wp, wp->w_hl_attr_normal, wrap);
|
||||||
if (wrap) {
|
if (wrap) {
|
||||||
ScreenGrid *current_grid = grid;
|
ScreenGrid *current_grid = grid;
|
||||||
int current_row = row;
|
int current_row = row, dummy_col = 0; // dummy_col unused
|
||||||
|
screen_adjust_grid(¤t_grid, ¤t_row, &dummy_col);
|
||||||
// if we're not in ext_multigrid mode, grid has not been allocated; keep
|
|
||||||
// working on the default_grid.
|
|
||||||
if (!ui_is_external(kUIMultigrid)) {
|
|
||||||
current_row += grid->row_offset;
|
|
||||||
current_grid = &default_grid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Force a redraw of the first column of the next line.
|
// Force a redraw of the first column of the next line.
|
||||||
current_grid->attrs[current_grid->line_offset[current_row+1]] = -1;
|
current_grid->attrs[current_grid->line_offset[current_row+1]] = -1;
|
||||||
@@ -4338,6 +4333,22 @@ win_line (
|
|||||||
return row;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Determine if dedicated window grid should be used or the default_grid
|
||||||
|
///
|
||||||
|
/// If UI did not request multigrid support, draw all windows on the
|
||||||
|
/// default_grid.
|
||||||
|
///
|
||||||
|
/// If the default_grid is used, adjust window relative positions to global
|
||||||
|
/// screen positions.
|
||||||
|
static void screen_adjust_grid(ScreenGrid **grid, int *row_off, int *col_off)
|
||||||
|
{
|
||||||
|
if (!ui_is_external(kUIMultigrid) && *grid != &default_grid) {
|
||||||
|
*row_off += (*grid)->row_offset;
|
||||||
|
*col_off += (*grid)->col_offset;
|
||||||
|
*grid = &default_grid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check whether the given character needs redrawing:
|
* Check whether the given character needs redrawing:
|
||||||
@@ -4385,6 +4396,7 @@ static void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol,
|
|||||||
// 2: occupies two display cells
|
// 2: occupies two display cells
|
||||||
int start_dirty = -1, end_dirty = 0;
|
int start_dirty = -1, end_dirty = 0;
|
||||||
|
|
||||||
|
// TODO(bfredl): check all callsites and eliminate
|
||||||
// Check for illegal row and col, just in case
|
// Check for illegal row and col, just in case
|
||||||
if (row >= grid->Rows) {
|
if (row >= grid->Rows) {
|
||||||
row = grid->Rows - 1;
|
row = grid->Rows - 1;
|
||||||
@@ -4393,12 +4405,7 @@ static void grid_put_linebuf(ScreenGrid *grid, int row, int coloff, int endcol,
|
|||||||
endcol = grid->Columns;
|
endcol = grid->Columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If UI is not externalized, merge the contents of global and window grids
|
screen_adjust_grid(&grid, &row, &coloff);
|
||||||
if (!ui_is_external(kUIMultigrid) && grid != &default_grid) {
|
|
||||||
row += grid->row_offset;
|
|
||||||
coloff += grid->col_offset;
|
|
||||||
grid = &default_grid;
|
|
||||||
}
|
|
||||||
|
|
||||||
off_from = 0;
|
off_from = 0;
|
||||||
off_to = grid->line_offset[row] + coloff;
|
off_to = grid->line_offset[row] + coloff;
|
||||||
@@ -5300,11 +5307,7 @@ static int grid_off2cells(ScreenGrid *grid, size_t off, size_t max_off)
|
|||||||
/// Caller must make sure "row" and "col" are not invalid!
|
/// Caller must make sure "row" and "col" are not invalid!
|
||||||
bool grid_lefthalve(ScreenGrid *grid, int row, int col)
|
bool grid_lefthalve(ScreenGrid *grid, int row, int col)
|
||||||
{
|
{
|
||||||
if (!ui_is_external(kUIMultigrid)) {
|
screen_adjust_grid(&grid, &row, &col);
|
||||||
row += grid->row_offset;
|
|
||||||
col += grid->col_offset;
|
|
||||||
grid = &default_grid;
|
|
||||||
}
|
|
||||||
|
|
||||||
return grid_off2cells(grid, grid->line_offset[row] + col,
|
return grid_off2cells(grid, grid->line_offset[row] + col,
|
||||||
grid->line_offset[row] + grid->Columns) > 1;
|
grid->line_offset[row] + grid->Columns) > 1;
|
||||||
@@ -5315,11 +5318,7 @@ bool grid_lefthalve(ScreenGrid *grid, int row, int col)
|
|||||||
int grid_fix_col(ScreenGrid *grid, int col, int row)
|
int grid_fix_col(ScreenGrid *grid, int col, int row)
|
||||||
{
|
{
|
||||||
int coloff = 0;
|
int coloff = 0;
|
||||||
if (!ui_is_external(kUIMultigrid)) {
|
screen_adjust_grid(&grid, &row, &coloff);
|
||||||
row += grid->row_offset;
|
|
||||||
coloff = grid->col_offset;
|
|
||||||
grid = &default_grid;
|
|
||||||
}
|
|
||||||
|
|
||||||
col += coloff;
|
col += coloff;
|
||||||
if (grid->chars != NULL && col > 0
|
if (grid->chars != NULL && col > 0
|
||||||
@@ -5345,11 +5344,8 @@ void grid_getbytes(ScreenGrid *grid, int row, int col, char_u *bytes,
|
|||||||
{
|
{
|
||||||
unsigned off;
|
unsigned off;
|
||||||
|
|
||||||
if (!ui_is_external(kUIMultigrid)) {
|
screen_adjust_grid(&grid, &row, &col);
|
||||||
row += grid->row_offset;
|
|
||||||
col += grid->col_offset;
|
|
||||||
grid = &default_grid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// safety check
|
// safety check
|
||||||
if (grid->chars != NULL && row < grid->Rows && col < grid->Columns) {
|
if (grid->chars != NULL && row < grid->Rows && col < grid->Columns) {
|
||||||
@@ -5406,12 +5402,7 @@ void grid_puts_len(ScreenGrid *grid, char_u *text, int textlen, int row,
|
|||||||
int need_redraw;
|
int need_redraw;
|
||||||
bool do_flush = false;
|
bool do_flush = false;
|
||||||
|
|
||||||
// If UI is not externalized, keep working on the default grid
|
screen_adjust_grid(&grid, &row, &col);
|
||||||
if (!ui_is_external(kUIMultigrid) && grid != &default_grid) {
|
|
||||||
row += grid->row_offset;
|
|
||||||
col += grid->col_offset;
|
|
||||||
grid = &default_grid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// safety check
|
// safety check
|
||||||
if (grid->chars == NULL || row >= grid->Rows || col >= grid->Columns) {
|
if (grid->chars == NULL || row >= grid->Rows || col >= grid->Columns) {
|
||||||
@@ -5552,7 +5543,8 @@ void grid_puts_line_flush(ScreenGrid *grid, bool set_cursor)
|
|||||||
assert(put_dirty_row != -1);
|
assert(put_dirty_row != -1);
|
||||||
if (put_dirty_first != -1) {
|
if (put_dirty_first != -1) {
|
||||||
if (set_cursor) {
|
if (set_cursor) {
|
||||||
ui_grid_cursor_goto(grid, put_dirty_row, put_dirty_last);
|
ui_grid_cursor_goto(grid->handle, put_dirty_row,
|
||||||
|
MIN(put_dirty_last, grid->Columns-1));
|
||||||
}
|
}
|
||||||
ui_line(grid, put_dirty_row, put_dirty_first, put_dirty_last,
|
ui_line(grid, put_dirty_row, put_dirty_first, put_dirty_last,
|
||||||
put_dirty_last, 0, false);
|
put_dirty_last, 0, false);
|
||||||
@@ -5866,14 +5858,12 @@ void grid_fill(ScreenGrid *grid, int start_row, int end_row, int start_col,
|
|||||||
{
|
{
|
||||||
schar_T sc;
|
schar_T sc;
|
||||||
|
|
||||||
// if grids are not externalized, keep working on the default_grid
|
int row_off = 0, col_off = 0;
|
||||||
if (!ui_is_external(kUIMultigrid) && grid != &default_grid) {
|
screen_adjust_grid(&grid, &row_off, &col_off);
|
||||||
start_row += grid->row_offset;
|
start_row += row_off;
|
||||||
end_row += grid->row_offset;
|
end_row += row_off;
|
||||||
start_col += grid->col_offset;
|
start_col += col_off;
|
||||||
end_col += grid->col_offset;
|
end_col += col_off;
|
||||||
grid = &default_grid;
|
|
||||||
}
|
|
||||||
|
|
||||||
// safety check
|
// safety check
|
||||||
if (end_row > grid->Rows) {
|
if (end_row > grid->Rows) {
|
||||||
@@ -6324,15 +6314,20 @@ void setcursor(void)
|
|||||||
{
|
{
|
||||||
if (redrawing()) {
|
if (redrawing()) {
|
||||||
validate_cursor();
|
validate_cursor();
|
||||||
int left_offset = curwin->w_wcol;
|
|
||||||
|
ScreenGrid *grid = &curwin->w_grid;
|
||||||
|
int row = curwin->w_wrow;
|
||||||
|
int col = curwin->w_wcol;
|
||||||
if (curwin->w_p_rl) {
|
if (curwin->w_p_rl) {
|
||||||
// With 'rightleft' set and the cursor on a double-wide character,
|
// With 'rightleft' set and the cursor on a double-wide character,
|
||||||
// position it on the leftmost column.
|
// position it on the leftmost column.
|
||||||
left_offset = curwin->w_grid.Columns - curwin->w_wcol
|
col = curwin->w_grid.Columns - curwin->w_wcol
|
||||||
- ((utf_ptr2cells(get_cursor_pos_ptr()) == 2
|
- ((utf_ptr2cells(get_cursor_pos_ptr()) == 2
|
||||||
&& vim_isprintc(gchar_cursor())) ? 2 : 1);
|
&& vim_isprintc(gchar_cursor())) ? 2 : 1);
|
||||||
}
|
}
|
||||||
ui_grid_cursor_goto(&curwin->w_grid, curwin->w_wrow, left_offset);
|
|
||||||
|
screen_adjust_grid(&grid, &row, &col);
|
||||||
|
ui_grid_cursor_goto(grid->handle, row, col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6404,13 +6399,10 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end, int col,
|
|||||||
int j;
|
int j;
|
||||||
unsigned temp;
|
unsigned temp;
|
||||||
|
|
||||||
// If UI is not externalized, keep working on default grid
|
int row_off = 0;
|
||||||
if (!ui_is_external(kUIMultigrid) && grid != &default_grid) {
|
screen_adjust_grid(&grid, &row_off, &col);
|
||||||
row += grid->row_offset;
|
row += row_off;
|
||||||
end += grid->row_offset;
|
end += row_off;
|
||||||
col += grid->col_offset;
|
|
||||||
grid = &default_grid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!screen_valid(TRUE) || line_count <= 0) {
|
if (!screen_valid(TRUE) || line_count <= 0) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
@@ -6459,13 +6451,10 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end, int col,
|
|||||||
int i;
|
int i;
|
||||||
unsigned temp;
|
unsigned temp;
|
||||||
|
|
||||||
// If UI is not externalized, keep working on default grid
|
int row_off = 0;
|
||||||
if (!ui_is_external(kUIMultigrid) && grid != &default_grid) {
|
screen_adjust_grid(&grid, &row_off, &col);
|
||||||
row += grid->row_offset;
|
row += row_off;
|
||||||
end += grid->row_offset;
|
end += row_off;
|
||||||
col += grid->col_offset;
|
|
||||||
grid = &default_grid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!screen_valid(TRUE) || line_count <= 0) {
|
if (!screen_valid(TRUE) || line_count <= 0) {
|
||||||
return FAIL;
|
return FAIL;
|
||||||
|
@@ -321,44 +321,37 @@ void ui_line(ScreenGrid *grid, int row, int startcol, int endcol, int clearcol,
|
|||||||
int clearattr, bool wrap)
|
int clearattr, bool wrap)
|
||||||
{
|
{
|
||||||
size_t off = grid->line_offset[row] + (size_t)startcol;
|
size_t off = grid->line_offset[row] + (size_t)startcol;
|
||||||
int row_off = ui_is_external(kUIMultigrid) ? 0 : grid->row_offset;
|
|
||||||
int col_off = ui_is_external(kUIMultigrid) ? 0 : grid->col_offset;
|
|
||||||
|
|
||||||
UI_CALL(raw_line, grid->handle, row_off + row, col_off + startcol,
|
UI_CALL(raw_line, grid->handle, row, startcol, endcol, clearcol, clearattr,
|
||||||
col_off + endcol, col_off + clearcol, clearattr, wrap,
|
wrap, (const schar_T *)grid->chars + off,
|
||||||
(const schar_T *)grid->chars + off,
|
|
||||||
(const sattr_T *)grid->attrs + off);
|
(const sattr_T *)grid->attrs + off);
|
||||||
|
|
||||||
if (p_wd) { // 'writedelay': flush & delay each time.
|
if (p_wd) { // 'writedelay': flush & delay each time.
|
||||||
int old_row = row, old_col = col;
|
int old_row = row, old_col = col;
|
||||||
|
handle_T old_grid = cursor_grid_handle;
|
||||||
// If'writedelay is active, we set the cursor to highlight what was drawn
|
// If'writedelay is active, we set the cursor to highlight what was drawn
|
||||||
ui_cursor_goto(row, MIN(clearcol, (int)Columns-1));
|
ui_grid_cursor_goto(grid->handle, row, MIN(clearcol, (int)Columns-1));
|
||||||
ui_flush();
|
ui_flush();
|
||||||
uint64_t wd = (uint64_t)labs(p_wd);
|
uint64_t wd = (uint64_t)labs(p_wd);
|
||||||
os_microdelay(wd * 1000u, true);
|
os_microdelay(wd * 1000u, true);
|
||||||
ui_cursor_goto(old_row, old_col);
|
ui_grid_cursor_goto(old_grid, old_row, old_col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_cursor_goto(int new_row, int new_col)
|
void ui_cursor_goto(int new_row, int new_col)
|
||||||
{
|
{
|
||||||
ui_grid_cursor_goto(&default_grid, new_row, new_col);
|
ui_grid_cursor_goto(DEFAULT_GRID_HANDLE, new_row, new_col);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_grid_cursor_goto(ScreenGrid *grid, int new_row, int new_col)
|
void ui_grid_cursor_goto(handle_T grid_handle, int new_row, int new_col)
|
||||||
{
|
{
|
||||||
new_row += ui_is_external(kUIMultigrid) ? 0 : grid->row_offset;
|
if (new_row == row && new_col == col && grid_handle == cursor_grid_handle) {
|
||||||
new_col += ui_is_external(kUIMultigrid) ? 0 : grid->col_offset;
|
|
||||||
int handle = ui_is_external(kUIMultigrid) ? grid->handle
|
|
||||||
: DEFAULT_GRID_HANDLE;
|
|
||||||
|
|
||||||
if (new_row == row && new_col == col && handle == cursor_grid_handle) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
row = new_row;
|
row = new_row;
|
||||||
col = new_col;
|
col = new_col;
|
||||||
cursor_grid_handle = handle;
|
cursor_grid_handle = grid_handle;
|
||||||
pending_cursor_update = true;
|
pending_cursor_update = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user