Rename context parameters to cx in movement.rs

This commit is contained in:
Max Brunsfeld 2021-05-28 15:06:32 -07:00
parent 765a8d0636
commit 71489251f4

View file

@ -2,34 +2,34 @@ use super::{Bias, DisplayMap, DisplayPoint, SelectionGoal};
use anyhow::Result;
use gpui::AppContext;
pub fn left(map: &DisplayMap, mut point: DisplayPoint, app: &AppContext) -> Result<DisplayPoint> {
pub fn left(map: &DisplayMap, mut point: DisplayPoint, cx: &AppContext) -> Result<DisplayPoint> {
if point.column() > 0 {
*point.column_mut() -= 1;
} else if point.row() > 0 {
*point.row_mut() -= 1;
*point.column_mut() = map.line_len(point.row(), app);
*point.column_mut() = map.line_len(point.row(), cx);
}
Ok(map.snapshot(app).clip_point(point, Bias::Left))
Ok(map.snapshot(cx).clip_point(point, Bias::Left))
}
pub fn right(map: &DisplayMap, mut point: DisplayPoint, app: &AppContext) -> Result<DisplayPoint> {
let max_column = map.line_len(point.row(), app);
pub fn right(map: &DisplayMap, mut point: DisplayPoint, cx: &AppContext) -> Result<DisplayPoint> {
let max_column = map.line_len(point.row(), cx);
if point.column() < max_column {
*point.column_mut() += 1;
} else if point.row() < map.max_point(app).row() {
} else if point.row() < map.max_point(cx).row() {
*point.row_mut() += 1;
*point.column_mut() = 0;
}
Ok(map.snapshot(app).clip_point(point, Bias::Right))
Ok(map.snapshot(cx).clip_point(point, Bias::Right))
}
pub fn up(
map: &DisplayMap,
mut point: DisplayPoint,
goal: SelectionGoal,
app: &AppContext,
cx: &AppContext,
) -> Result<(DisplayPoint, SelectionGoal)> {
let map = map.snapshot(app);
let map = map.snapshot(cx);
let goal_column = if let SelectionGoal::Column(column) = goal {
column
} else {
@ -50,10 +50,10 @@ pub fn down(
map: &DisplayMap,
mut point: DisplayPoint,
goal: SelectionGoal,
app: &AppContext,
cx: &AppContext,
) -> Result<(DisplayPoint, SelectionGoal)> {
let max_point = map.max_point(app);
let map = map.snapshot(app);
let max_point = map.max_point(cx);
let map = map.snapshot(cx);
let goal_column = if let SelectionGoal::Column(column) = goal {
column
} else {
@ -74,9 +74,9 @@ pub fn line_beginning(
map: &DisplayMap,
point: DisplayPoint,
toggle_indent: bool,
app: &AppContext,
cx: &AppContext,
) -> Result<DisplayPoint> {
let (indent, is_blank) = map.line_indent(point.row(), app);
let (indent, is_blank) = map.line_indent(point.row(), cx);
if toggle_indent && !is_blank && point.column() != indent {
Ok(DisplayPoint::new(point.row(), indent))
} else {
@ -84,30 +84,30 @@ pub fn line_beginning(
}
}
pub fn line_end(map: &DisplayMap, point: DisplayPoint, app: &AppContext) -> Result<DisplayPoint> {
pub fn line_end(map: &DisplayMap, point: DisplayPoint, cx: &AppContext) -> Result<DisplayPoint> {
Ok(DisplayPoint::new(
point.row(),
map.line_len(point.row(), app),
map.line_len(point.row(), cx),
))
}
pub fn prev_word_boundary(
map: &DisplayMap,
point: DisplayPoint,
app: &AppContext,
cx: &AppContext,
) -> Result<DisplayPoint> {
if point.column() == 0 {
if point.row() == 0 {
Ok(DisplayPoint::new(0, 0))
} else {
let row = point.row() - 1;
Ok(DisplayPoint::new(row, map.line_len(row, app)))
Ok(DisplayPoint::new(row, map.line_len(row, cx)))
}
} else {
let mut boundary = DisplayPoint::new(point.row(), 0);
let mut column = 0;
let mut prev_c = None;
for c in map.snapshot(app).chars_at(boundary) {
for c in map.snapshot(cx).chars_at(boundary) {
if column >= point.column() {
break;
}
@ -126,10 +126,10 @@ pub fn prev_word_boundary(
pub fn next_word_boundary(
map: &DisplayMap,
mut point: DisplayPoint,
app: &AppContext,
cx: &AppContext,
) -> Result<DisplayPoint> {
let mut prev_c = None;
for c in map.snapshot(app).chars_at(point) {
for c in map.snapshot(cx).chars_at(point) {
if prev_c.is_some() && (c == '\n' || char_kind(prev_c.unwrap()) != char_kind(c)) {
break;
}