Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
sodium
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Frans Klaver
sodium
Commits
22c312a9
Commit
22c312a9
authored
7 years ago
by
Jeremy Soller
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #81 from dummie999/master
Make buffers behave more consistent
parents
e656ba57
c1558262
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/core/prompt.rs
+17
-0
17 additions, 0 deletions
src/core/prompt.rs
src/state/editor.rs
+4
-2
4 additions, 2 deletions
src/state/editor.rs
with
21 additions
and
2 deletions
src/core/prompt.rs
+
17
−
0
View file @
22c312a9
...
...
@@ -39,6 +39,8 @@ pub enum PromptCommand<'a> {
},
/// List the available buffers.
ListBuffers
,
/// Create a new empty buffer.
CreateBuffer
,
/// Delete the current buffer.
DeleteBuffer
,
/// Switch to the nth buffer.
...
...
@@ -70,6 +72,7 @@ impl<'a> PromptCommand<'a> {
"o"
|
"open"
=>
Open
{
path
:
sec_cmd
},
"w"
|
"write"
=>
Write
{
path
:
sec_cmd
},
"ls"
=>
ListBuffers
,
"bn"
=>
CreateBuffer
,
"bd"
=>
DeleteBuffer
,
"h"
|
"help"
=>
Help
,
"q"
|
"quit"
=>
Quit
,
...
...
@@ -121,10 +124,16 @@ impl Editor {
}
}
Open
{
path
}
=>
{
let
line
=
self
.buffers
.current_buffer
()
.get_line
(
0
)
.unwrap
()
.len
();
let
empty
=
self
.buffers
.current_buffer
()
.len
()
==
1
&&
line
==
0
;
let
ix
=
self
.buffers
.current_buffer_index
();
self
.status_bar.msg
=
match
self
.open
(
path
)
{
FileStatus
::
NotFound
=>
format!
(
"File {} could not be opened"
,
path
),
FileStatus
::
Ok
=>
format!
(
"File {} opened"
,
path
),
_
=>
unreachable!
(),
};
if
empty
{
self
.buffers
.delete_buffer
(
ix
);
}
}
Write
{
path
}
=>
{
...
...
@@ -151,11 +160,19 @@ impl Editor {
}
SwitchToBuffer
{
buffer_index
:
ix
}
=>
if
!
self
.buffers
.is_buffer_index_valid
(
ix
)
{
self
.status_bar.msg
=
format!
(
"Invalid buffer #{}"
,
ix
);
}
else
if
self
.buffers
.current_buffer_index
()
==
ix
{
self
.status_bar.msg
=
format!
(
"Already in buffer #{}"
,
ix
);
}
else
{
self
.buffers
.switch_to
(
ix
);
self
.redraw_task
=
RedrawTask
::
Full
;
self
.status_bar.msg
=
format!
(
"Switched to buffer #{}"
,
ix
);
},
CreateBuffer
=>
{
let
new
=
self
.buffers
.new_buffer
(
Buffer
::
new
());
self
.buffers
.switch_to
(
new
);
self
.redraw_task
=
RedrawTask
::
Full
;
self
.status_bar.msg
=
format!
(
"Switched to buffer#{}"
,
new
);
}
DeleteBuffer
=>
{
let
ix
=
self
.buffers
.current_buffer_index
();
self
.buffers
.delete_buffer
(
ix
);
...
...
This diff is collapsed.
Click to expand it.
src/state/editor.rs
+
4
−
2
View file @
22c312a9
...
...
@@ -38,7 +38,7 @@ pub struct Buffer {
impl
Buffer
{
/// Create a new Buffer with default values.
fn
new
()
->
Buffer
{
pub
fn
new
()
->
Buffer
{
Buffer
{
raw_buffer
:
SplitBuffer
::
new
(),
current_cursor
:
0
,
...
...
@@ -147,7 +147,9 @@ impl BufferManager {
if
self
.buffers
.len
()
==
0
{
self
.buffers
.push
(
Buffer
::
new
());
self
.current_buffer_index
=
0
;
}
else
if
self
.current_buffer_index
<=
n
{
}
else
if
n
==
0
{
self
.current_buffer_index
=
0
;
}
else
if
self
.current_buffer_index
>=
n
{
self
.current_buffer_index
-=
1
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment