diff options
author | Utkarsh Maheshwari <utkarshme96@gmail.com> | 2018-06-19 11:45:10 +0530 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2018-12-31 12:44:22 +0100 |
commit | 0432e1586ef0f9dd5e473cee07787ed5bb880570 (patch) | |
tree | 59cf7c82d37a9335fe74f48e94e58861c16df939 /src | |
parent | d5754eae020d672b4f6c62b636a56e0d6d56b4dc (diff) | |
download | rneovim-0432e1586ef0f9dd5e473cee07787ed5bb880570.tar.gz rneovim-0432e1586ef0f9dd5e473cee07787ed5bb880570.tar.bz2 rneovim-0432e1586ef0f9dd5e473cee07787ed5bb880570.zip |
multigrid: Put everything on default_grid if not ext_multigrid
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/ui.c | 4 | ||||
-rw-r--r-- | src/nvim/globals.h | 2 | ||||
-rw-r--r-- | src/nvim/screen.c | 96 | ||||
-rw-r--r-- | src/nvim/ui.c | 11 |
4 files changed, 82 insertions, 31 deletions
diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 18befd498f..4f56371633 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -257,9 +257,7 @@ void nvim_ui_try_resize_grid(uint64_t channel_id, Integer grid, Integer width, return; } - // TODO(utkarshme): Check if grid exists - - ui_grid_resize((GridHandle)grid, (int)width, (int)height); + ui_grid_resize((GridHandle)grid, (int)width, (int)height, error); } /// Pushes data into UI.UIData, to be consumed later by remote_ui_flush(). diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 57d14d650c..7e17136528 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -164,6 +164,8 @@ EXTERN int screen_Columns INIT(= 0); /* actual size of ScreenLines[] */ EXTERN ScreenGrid default_grid INIT(= { 0, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0 }); +#define DEFAULT_GRID_HANDLE 1 /* handle for the default_grid */ + /* * When vgetc() is called, it sets mod_mask to the set of modifiers that are * held down based on the MOD_MASK_* symbols that are read first. diff --git a/src/nvim/screen.c b/src/nvim/screen.c index f247aa707d..c248977df5 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -118,11 +118,11 @@ #define MB_FILLER_CHAR '<' /* character used when a double-width character * doesn't fit. */ +#define W_ENDCOL(wp) (wp->w_wincol + wp->w_width) +#define W_ENDROW(wp) (wp->w_winrow + wp->w_height) -#define W_ENDCOL(wp) (wp->w_width + wp->w_wincol) -#define W_ENDROW(wp) (wp->w_height + wp->w_winrow) - -#define DEFAULT_GRID_HANDLE 1 +// Get the offset for the current line buffer when redrawing a line for a grid +#define GRID_TMPLINE(grid) ((grid)->Rows * (grid)->Columns) static match_T search_hl; /* used for 'hlsearch' highlight matching */ @@ -1772,7 +1772,7 @@ static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T * 6. set highlighting for the Visual area an other text */ col = 0; - off = (int)(grid->Rows * grid->Columns); + off = (int)GRID_TMPLINE(grid); /* * 1. Add the cmdwin_type for the command-line window @@ -2674,7 +2674,7 @@ win_line ( cur = cur->next; } - off = (unsigned)(grid->Rows * grid->Columns); + off = (unsigned)GRID_TMPLINE(grid); int col = 0; // Visual column on screen. if (wp->w_p_rl) { // Rightleft window: process the text in the normal direction, but put @@ -4274,7 +4274,7 @@ win_line ( } col = 0; - off = (unsigned)(grid->Rows * grid->Columns); + off = (unsigned)GRID_TMPLINE(grid); if (wp->w_p_rl) { col = grid->Columns - 1; /* col is not used if breaking! */ off += col; @@ -4366,7 +4366,20 @@ static void grid_move_line(ScreenGrid *grid, int row, int coloff, int endcol, if (endcol > grid->Columns) endcol = grid->Columns; - off_from = (unsigned)(grid->Rows * grid->Columns); + // If UI is not externalized, merge the contents of global and window grids + if (!ui_is_external(kUIMultigrid) && grid != &default_grid) { + row += grid->OffsetRow; + coloff += grid->OffsetColumn; + memcpy(default_grid.ScreenLines + GRID_TMPLINE(&default_grid), + grid->ScreenLines + GRID_TMPLINE(grid), + sizeof(schar_T) * grid->Columns); + memcpy(default_grid.ScreenAttrs + GRID_TMPLINE(&default_grid), + grid->ScreenAttrs + GRID_TMPLINE(grid), + sizeof(sattr_T) * grid->Columns); + grid = &default_grid; + } + + off_from = (unsigned)GRID_TMPLINE(grid); off_to = grid->LineOffset[row] + coloff; max_off_from = off_from + grid->Columns; max_off_to = grid->LineOffset[row] + grid->Columns; @@ -4460,21 +4473,22 @@ static void grid_move_line(ScreenGrid *grid, int row, int coloff, int endcol, // blank out the rest of the line // TODO(bfredl): we could cache winline widths while (col < clear_width) { - if (grid->ScreenLines[off_to][0] != ' ' || grid->ScreenLines[off_to][1] != NUL - || grid->ScreenAttrs[off_to] != bg_attr) { - grid->ScreenLines[off_to][0] = ' '; - grid->ScreenLines[off_to][1] = NUL; - grid->ScreenAttrs[off_to] = bg_attr; - if (start_dirty == -1) { - start_dirty = col; - end_dirty = col; - } else if (clear_end == -1) { - end_dirty = endcol; - } - clear_end = col+1; + if (grid->ScreenLines[off_to][0] != ' ' + || grid->ScreenLines[off_to][1] != NUL + || grid->ScreenAttrs[off_to] != bg_attr) { + grid->ScreenLines[off_to][0] = ' '; + grid->ScreenLines[off_to][1] = NUL; + grid->ScreenAttrs[off_to] = bg_attr; + if (start_dirty == -1) { + start_dirty = col; + end_dirty = col; + } else if (clear_end == -1) { + end_dirty = endcol; } - col++; - off_to++; + clear_end = col+1; + } + col++; + off_to++; } } @@ -5111,7 +5125,7 @@ win_redr_custom ( *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); } - col += wp->w_winrow; + col += wp->w_wincol; } if (maxwidth <= 0) @@ -5258,7 +5272,9 @@ void grid_getbytes(ScreenGrid *grid, int row, int col, char_u *bytes, { unsigned off; - if (grid == NULL) { + if (!ui_is_external(kUIMultigrid)) { + row += grid->OffsetRow; + col += grid->OffsetColumn; grid = &default_grid; } @@ -5321,6 +5337,13 @@ void grid_puts_len(ScreenGrid *grid, char_u *text, int textlen, int row, grid = &default_grid; } + // If UI is not externalized, keep working on the default grid + if (!ui_is_external(kUIMultigrid) && grid != &default_grid) { + row += grid->OffsetRow; + col += grid->OffsetColumn; + grid = &default_grid; + } + // safety check if (grid->ScreenLines == NULL || row >= grid->Rows || col >= grid->Columns) { return; @@ -5777,6 +5800,15 @@ void grid_fill(ScreenGrid *grid, int start_row, int end_row, int start_col, grid = &default_grid; } + // if grids are not externalized, keep working on the default_grid + if (!ui_is_external(kUIMultigrid) && grid != &default_grid) { + start_row += grid->OffsetRow; + end_row += grid->OffsetRow; + start_col += grid->OffsetColumn; + end_col += grid->OffsetColumn; + grid = &default_grid; + } + if (end_row > grid->Rows) // safety check end_row = grid->Rows; if (end_col > grid->Columns) // safety check @@ -6275,6 +6307,14 @@ int grid_ins_lines(ScreenGrid *grid, int row, int line_count, int end, grid = &default_grid; } + // If UI is not externalized, keep working on default grid + if (!ui_is_external(kUIMultigrid) && grid != &default_grid) { + row += grid->OffsetRow; + end += grid->OffsetRow; + col += grid->OffsetColumn; + grid = &default_grid; + } + if (!screen_valid(TRUE) || line_count <= 0) { return FAIL; } @@ -6326,6 +6366,14 @@ int grid_del_lines(ScreenGrid *grid, int row, int line_count, int end, grid = &default_grid; } + // If UI is not externalized, keep working on default grid + if (!ui_is_external(kUIMultigrid) && grid != &default_grid) { + row += grid->OffsetRow; + end += grid->OffsetRow; + col += grid->OffsetColumn; + grid = &default_grid; + } + if (!screen_valid(TRUE) || line_count <= 0) { return FAIL; } diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 24557c5d0b..74814bf0ae 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -440,13 +440,16 @@ Array ui_array(void) return all_uis; } -void ui_grid_resize(GridHandle grid_handle, int width, int height) +void ui_grid_resize(GridHandle grid_handle, int width, int height, Error *error) { - win_T *wp = get_win_by_grid_handle(grid_handle); + if (grid_handle == DEFAULT_GRID_HANDLE) { + screen_resize(width, height); + return; + } + win_T *wp = get_win_by_grid_handle(grid_handle); if (wp == NULL) { - //TODO(utkarshme): error out - abort(); + api_set_error(error, kErrorTypeValidation, "No window with the given handle"); return; } |