Skip to content

Commit

Permalink
Fix for selection expanding on move line up
Browse files Browse the repository at this point in the history
  • Loading branch information
nangtrongvuon committed Oct 1, 2018
1 parent 86e77bc commit 601bd20
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions rust/core-lib/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// distributed under the License is distributed on an "AS IS" BASIS,
// limitations under the License.

use std::borrow::{Borrow, Cow};
Expand Down Expand Up @@ -544,11 +544,11 @@ impl Editor {
if start_line == 0 { continue }
// line to swap moved lines/regions with
let swap_line = start_line - 1;
let (_, end) = view.get_line_offset(&self.text, end_line);
let (start, _) = view.get_line_offset(&self.text, end_line + 1);
let (swap_start, swap_end) = view.get_line_offset(&self.text, swap_line);

let swap_iv = Interval::new_closed_closed(swap_start, swap_end);
let iv = Interval::new_closed_open(end, end);
let iv = Interval::new_closed_open(start, start);
let mut saved_text = Rope::from(self.text.slice_to_string(swap_start..swap_end));

// adjusts newline character for last line
Expand All @@ -559,12 +559,7 @@ impl Editor {
builder.delete(swap_iv);
builder.replace(iv, saved_text);
}
// If selection contains the last offset, we use the before caret edit type.
if view.sel_regions().last().unwrap().end == self.text.len() {
self.this_edit_type = EditType::CaretBefore;
} else {
self.this_edit_type = EditType::Other;
}
self.this_edit_type = EditType::CaretBefore;
self.add_delta(builder.build());
}

Expand Down Expand Up @@ -616,7 +611,6 @@ impl Editor {
// n..n.
let start = range.start;
let end = range.end - 1;
eprintln!("{:?} {:?} ", start, end);
if let Some((p_start, p_end)) = prev_sel.take() {
// Lines selected are continuous, thus we merge them.
// e.g 1..2 and 2..3 becomes 1..3
Expand All @@ -634,6 +628,7 @@ impl Editor {
if let Some(last) = prev_sel.take() {
ranges.push(last);
}
eprintln!("{:?}", ranges);
ranges
}

Expand Down

0 comments on commit 601bd20

Please sign in to comment.