git://git.nikiroo.be
/
nikiroo-utils.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
01fccda
)
#35 editor wip
author
Kevin Lamonte
<kevin.lamonte@gmail.com>
Thu, 15 Aug 2019 01:31:27 +0000
(20:31 -0500)
committer
Kevin Lamonte
<kevin.lamonte@gmail.com>
Thu, 15 Aug 2019 01:31:27 +0000
(20:31 -0500)
src/jexer/TEditorWidget.java
patch
|
blob
|
blame
|
history
src/jexer/teditor/Document.java
patch
|
blob
|
blame
|
history
src/jexer/teditor/Highlighter.java
patch
|
blob
|
blame
|
history
src/jexer/teditor/Line.java
patch
|
blob
|
blame
|
history
src/jexer/teditor/Word.java
patch
|
blob
|
blame
|
history
diff --git
a/src/jexer/TEditorWidget.java
b/src/jexer/TEditorWidget.java
index 204b5750d3faa09d7c7c7a2f8b81460801195db8..32263de5dab555ad1e829310c815696d66f37fc3 100644
(file)
--- a/
src/jexer/TEditorWidget.java
+++ b/
src/jexer/TEditorWidget.java
@@
-266,7
+266,7
@@
public class TEditorWidget extends TWidget {
) {
// Plain old keystroke, process it
// TODO: fix document to use ints, not chars
) {
// Plain old keystroke, process it
// TODO: fix document to use ints, not chars
- document.addChar(
(char)
keypress.getKey().getChar());
+ document.addChar(keypress.getKey().getChar());
alignCursor();
} else {
// Pass other keys (tab etc.) on to TWidget
alignCursor();
} else {
// Pass other keys (tab etc.) on to TWidget
diff --git
a/src/jexer/teditor/Document.java
b/src/jexer/teditor/Document.java
index 9b0453860327b67ecfa5837ffa4966b5008854fe..159a95f6d95252cc4a01f7903d476ba784ce149a 100644
(file)
--- a/
src/jexer/teditor/Document.java
+++ b/
src/jexer/teditor/Document.java
@@
-430,7
+430,7
@@
public class Document {
*
* @param ch the character to replace or insert
*/
*
* @param ch the character to replace or insert
*/
- public void addChar(final
char
ch) {
+ public void addChar(final
int
ch) {
dirty = true;
if (overwrite) {
lines.get(lineNumber).replaceChar(ch);
dirty = true;
if (overwrite) {
lines.get(lineNumber).replaceChar(ch);
diff --git
a/src/jexer/teditor/Highlighter.java
b/src/jexer/teditor/Highlighter.java
index 4f601556c5d0ffd4c94d7fed98698f2c11247d63..a48419455e541697e12da7dfd81ebb8db52d7e9e 100644
(file)
--- a/
src/jexer/teditor/Highlighter.java
+++ b/
src/jexer/teditor/Highlighter.java
@@
-69,11
+69,13
@@
public class Highlighter {
* @param ch the character
* @return true if the word should be split
*/
* @param ch the character
* @return true if the word should be split
*/
- public boolean shouldSplit(final
char
ch) {
+ public boolean shouldSplit(final
int
ch) {
// For now, split on punctuation
String punctuation = "'\"\\<>{}[]!@#$%^&*();:.,-+/*?";
// For now, split on punctuation
String punctuation = "'\"\\<>{}[]!@#$%^&*();:.,-+/*?";
- if (punctuation.indexOf(ch) != -1) {
- return true;
+ if (ch < 0x100) {
+ if (punctuation.indexOf((char) ch) != -1) {
+ return true;
+ }
}
return false;
}
}
return false;
}
diff --git
a/src/jexer/teditor/Line.java
b/src/jexer/teditor/Line.java
index 965c38f84a421986cd753c8b42f74cdfcd7228bf..345cfcdfd5048ad1c12b0d5622cca11d157cf1f3 100644
(file)
--- a/
src/jexer/teditor/Line.java
+++ b/
src/jexer/teditor/Line.java
@@
-32,6
+32,7
@@
import java.util.ArrayList;
import java.util.List;
import jexer.bits.CellAttributes;
import java.util.List;
import jexer.bits.CellAttributes;
+import jexer.bits.StringUtils;
/**
* A Line represents a single line of text on the screen, as a collection of
/**
* A Line represents a single line of text on the screen, as a collection of
@@
-145,7
+146,7
@@
public class Line {
* @return the number of cells needed to display this line
*/
public int getDisplayLength() {
* @return the number of cells needed to display this line
*/
public int getDisplayLength() {
- int n =
rawText.length(
);
+ int n =
StringUtils.width(rawText.toString()
);
// For now just return the raw text length.
if (n > 0) {
// For now just return the raw text length.
if (n > 0) {
@@
-172,8
+173,9
@@
public class Line {
words.clear();
Word word = new Word(this.defaultColor, this.highlighter);
words.add(word);
words.clear();
Word word = new Word(this.defaultColor, this.highlighter);
words.add(word);
- for (int i = 0; i < rawText.length(); i++) {
- char ch = rawText.charAt(i);
+ for (int i = 0; i < rawText.length();) {
+ int ch = rawText.codePointAt(i);
+ i += Character.charCount(ch);
Word newWord = word.addChar(ch);
if (newWord != word) {
words.add(newWord);
Word newWord = word.addChar(ch);
if (newWord != word) {
words.add(newWord);
@@
-194,7
+196,7
@@
public class Line {
if (cursor == 0) {
return false;
}
if (cursor == 0) {
return false;
}
- cursor
--
;
+ cursor
-= StringUtils.width(rawText.codePointAt(cursor - 1))
;
return true;
}
return true;
}
@@
-210,7
+212,11
@@
public class Line {
if (cursor == getDisplayLength() - 1) {
return false;
}
if (cursor == getDisplayLength() - 1) {
return false;
}
- cursor++;
+ if (cursor < getDisplayLength()) {
+ cursor += StringUtils.width(rawText.codePointAt(cursor));
+ } else {
+ cursor++;
+ }
return true;
}
return true;
}
@@
-250,7
+256,9
@@
public class Line {
assert (words.size() > 0);
if (cursor < getDisplayLength()) {
assert (words.size() > 0);
if (cursor < getDisplayLength()) {
- rawText.deleteCharAt(cursor);
+ for (int i = 0; i < Character.charCount(rawText.charAt(cursor)); i++) {
+ rawText.deleteCharAt(cursor);
+ }
}
// Re-scan the line to determine the new word boundaries.
}
// Re-scan the line to determine the new word boundaries.
@@
-271,11
+279,11
@@
public class Line {
*
* @param ch the character to insert
*/
*
* @param ch the character to insert
*/
- public void addChar(final
char
ch) {
+ public void addChar(final
int
ch) {
if (cursor < getDisplayLength() - 1) {
if (cursor < getDisplayLength() - 1) {
- rawText.insert(cursor,
ch
);
+ rawText.insert(cursor,
Character.toChars(ch)
);
} else {
} else {
- rawText.append(
ch
);
+ rawText.append(
Character.toChars(ch)
);
}
scanLine();
cursor++;
}
scanLine();
cursor++;
@@
-286,11
+294,14
@@
public class Line {
*
* @param ch the character to replace
*/
*
* @param ch the character to replace
*/
- public void replaceChar(final
char
ch) {
+ public void replaceChar(final
int
ch) {
if (cursor < getDisplayLength() - 1) {
if (cursor < getDisplayLength() - 1) {
- rawText.setCharAt(cursor, ch);
+ for (int i = 0; i < Character.charCount(rawText.charAt(cursor)); i++) {
+ rawText.deleteCharAt(cursor);
+ }
+ rawText.insert(cursor, Character.toChars(ch));
} else {
} else {
- rawText.append(
ch
);
+ rawText.append(
Character.toChars(ch)
);
}
scanLine();
cursor++;
}
scanLine();
cursor++;
diff --git
a/src/jexer/teditor/Word.java
b/src/jexer/teditor/Word.java
index ffb11aa1a520d9b37ca76eee98f776f9509794d9..eada29cff83ed8b1c61c59d1741b5646d1f645b8 100644
(file)
--- a/
src/jexer/teditor/Word.java
+++ b/
src/jexer/teditor/Word.java
@@
-29,6
+29,7
@@
package jexer.teditor;
import jexer.bits.CellAttributes;
package jexer.teditor;
import jexer.bits.CellAttributes;
+import jexer.bits.StringUtils;
/**
* A Word represents text that was entered by the user. It can be either
/**
* A Word represents text that was entered by the user. It can be either
@@
-76,12
+77,12
@@
public class Word {
* @param defaultColor the color for unhighlighted text
* @param highlighter the highlighter to use
*/
* @param defaultColor the color for unhighlighted text
* @param highlighter the highlighter to use
*/
- public Word(final
char
ch, final CellAttributes defaultColor,
+ public Word(final
int
ch, final CellAttributes defaultColor,
final Highlighter highlighter) {
this.defaultColor = defaultColor;
this.highlighter = highlighter;
final Highlighter highlighter) {
this.defaultColor = defaultColor;
this.highlighter = highlighter;
- text.append(
ch
);
+ text.append(
Character.toChars(ch)
);
}
/**
}
/**
@@
-139,7
+140,7
@@
public class Word {
// TODO: figure out how to handle the tab character. Do we have a
// global tab stops list and current word position?
// TODO: figure out how to handle the tab character. Do we have a
// global tab stops list and current word position?
- return
text.length(
);
+ return
StringUtils.width(text.toString()
);
}
/**
}
/**
@@
-184,9
+185,9
@@
public class Word {
* @return either this word (if it was added), or a new word that
* contains ch
*/
* @return either this word (if it was added), or a new word that
* contains ch
*/
- public Word addChar(final
char
ch) {
+ public Word addChar(final
int
ch) {
if (text.length() == 0) {
if (text.length() == 0) {
- text.append(
ch
);
+ text.append(
Character.toChars(ch)
);
return this;
}
return this;
}
@@
-205,14
+206,14
@@
public class Word {
&& Character.isWhitespace(ch)
) {
// Adding to a whitespace word, keep at it.
&& Character.isWhitespace(ch)
) {
// Adding to a whitespace word, keep at it.
- text.append(
ch
);
+ text.append(
Character.toChars(ch)
);
return this;
}
if (!Character.isWhitespace(text.charAt(0))
&& !Character.isWhitespace(ch)
) {
// Adding to a non-whitespace word, keep at it.
return this;
}
if (!Character.isWhitespace(text.charAt(0))
&& !Character.isWhitespace(ch)
) {
// Adding to a non-whitespace word, keep at it.
- text.append(
ch
);
+ text.append(
Character.toChars(ch)
);
return this;
}
return this;
}