Skip to content

Commit

Permalink
Show selections
Browse files Browse the repository at this point in the history
  • Loading branch information
nviennot committed Nov 25, 2019
1 parent 7600187 commit 5a30905
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
30 changes: 30 additions & 0 deletions assets/js/term/pane.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ export default class Pane extends React.Component {
this.props.session.get_pane_event_buffer(this.props.id).set_handler({
on_pty_data: this.on_pty_data.bind(this),
on_bootstrap_grid: this.on_bootstrap_grid.bind(this),
on_sync_copy_mode: this.on_sync_copy_mode.bind(this),
})
}
}
Expand Down Expand Up @@ -108,6 +109,35 @@ export default class Pane extends React.Component {
on_pty_data(data) {
this.term.write(data)
}

on_sync_copy_mode(data) {
const term = this.term
const select = term._core._selectionService;
const top_line_offset = term.buffer._buffer.lines.length - term.rows;

if (data && data.length == 0) {
term._core.buffer.ydisp = top_line_offset
select.clearSelection();
term.refresh(0, term.rows-1);
return;
}

let [backing, oy, cx, cy, sel, status] = data;

if (sel && sel.length > 0) {
let [selx, sely, flags] = sel
sely = term.rows - sely
select._model.selectionStart = [cx+1, top_line_offset + cy-oy]
select._model.selectionEnd = [selx, top_line_offset + sely-1]
select.refresh();
}

let new_ydisp = Math.max(top_line_offset - oy, 0)
if (term._core.buffer.ydisp != new_ydisp) {
term._core.buffer.ydisp = new_ydisp;
term.refresh(0, term.rows-1);
}
}
}

const bootstrap_grid = (term, cursor_pos, mode, grid_data) => {
Expand Down
5 changes: 5 additions & 0 deletions assets/js/term/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default class Session extends React.Component {
this.daemon_handlers.set(TMATE_OUT_PTY_DATA, this.on_pty_data)
this.daemon_handlers.set(TMATE_OUT_STATUS, this.on_status)
this.daemon_handlers.set(TMATE_OUT_FIN, this.on_fin)
this.daemon_handlers.set(TMATE_OUT_SYNC_COPY_MODE, this.on_sync_copy_mode)

this.pane_events = new Map()

Expand Down Expand Up @@ -209,6 +210,10 @@ export default class Session extends React.Component {
this.emit_pane_event(pane_id, "on_pty_data", data)
}

on_sync_copy_mode(pane_id, data) {
this.emit_pane_event(pane_id, "on_sync_copy_mode", data)
}

render_message(msg) {
return <div className="session-status">
<h3>{msg}</h3>
Expand Down

0 comments on commit 5a30905

Please sign in to comment.