GithubHelp home page GithubHelp logo

rosemoe / sora-editor Goto Github PK

View Code? Open in Web Editor NEW
908.0 25.0 134.0 12.63 MB

A multifunctional Android code editor library. (aka CodeEditor)

License: GNU Lesser General Public License v2.1

Java 73.47% Kotlin 23.10% Lua 3.22% Scheme 0.20%
android autocomplete customview syntax-highlighting code-editor codeeditor

sora-editor's Introduction

Banner

CI GitHub license Maven Central
Telegram QQ

sora-editor is a cool and optimized code editor on Android platform

Read this in other languages: English, 简体中文, Español, 日本語.

Note that statements in other languages may not be up-to-date.

Work In Progress This project is still developing slowly.

Issues and pull requests are welcome.

Features

  • Incremental syntax highlight
  • Auto-completion (with code snippets)
  • Auto indent
  • Code block lines
  • Scale text
  • Undo/redo
  • Search and replace
  • Auto wordwrap
  • Show non-printable characters
  • Diagnostic markers
  • Text magnifier
  • Sticky Scroll
  • Highlight bracket pairs
  • Event System
  • TextMate and TreeSitter support

Documentation

To quickly get started, please view this Quickstart Guide.

To check out all docs, please visit Documentation Site.

Screenshots

GeneralAppearance ProblemIndicator

Discuss

Contributors

License

sora-editor - the awesome code editor for Android
https://github.com/Rosemoe/sora-editor
Copyright (C) 2020-2024  Rosemoe

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301
USA

Please contact Rosemoe by email [email protected] if you need
additional information or have any questions

Acknowledgements

Thanks to JetBrains for allocating free open-source licences for IDEs such as IntelliJ IDEA.

sora-editor's People

Contributors

co2mega avatar coyamo avatar dependabot[bot] avatar dingyi222666 avatar eazed-yu avatar elcosilol9 avatar ikws4 avatar itsaky avatar keta1 avatar liyujiang-gzu avatar m-anshuman2166 avatar martlintz avatar massivemadness avatar mnixry avatar muntashirakon avatar ninjacoderhsi avatar omeraydindev avatar pranavpurwar avatar randunuk avatar randunurtx avatar renovate[bot] avatar rosemoe avatar starkzhidian avatar summerain0 avatar tegajoel avatar tyron12233 avatar yuruxuan avatar zeroaicy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sora-editor's Issues

Enhance text selection method

Hi,
the method that this editor has isn't good. it's not smooth as well as it is hard to move the cursor and many other issues compared with the default android text selection method. so it would be way better if you use the default text selection method rather than a custom one (if possible). keep in mind that it offers many editing options such as cope, paste, select all, and much more.

The CodeEditor should auto scroll horizontally when dragging selection/insert handle

Currently, the CodeEditor only scrolls vertically (upward and downward) if the selection handle or insert handle is being moved by the user. The same behaviour should also be implemented when moved horizontally.

When moving the insert handle horizontally to the right, the CodeEditor scrolls. But this behaviour doesn't seem to be implemented for handle moving horizontally to the left.

Horizontal scroll doesn't work when moving the selection handles horizontally (both left and right).

输入(){}后,在花括号中间按回车再按回退键,崩溃日志

java.lang.StringIndexOutOfBoundsException: String index out of range: -1
        at java.lang.AbstractStringBuilder.substring(AbstractStringBuilder.java:954)
        at java.lang.StringBuilder.substring(StringBuilder.java:77)
        at java.lang.AbstractStringBuilder.substring(AbstractStringBuilder.java:900)
        at java.lang.StringBuilder.substring(StringBuilder.java:77)
        at io.github.rosemoe.editor.text.Content.subContent(Content.java:528)
        at io.github.rosemoe.editor.text.Content.subSequence(Content.java:129)
        at io.github.rosemoe.editor.widget.EditorInputConnection.getTextRegionInternal(EditorInputConnection.java:115)
        at io.github.rosemoe.editor.widget.EditorInputConnection.getTextRegion(EditorInputConnection.java:124)
        at io.github.rosemoe.editor.widget.EditorInputConnection.getTextAfterCursor(EditorInputConnection.java:141)
        at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:255)
        at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:94)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:224)
        at android.app.ActivityThread.main(ActivityThread.java:7053)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:536)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:876)

CodeEditor.java的drawLineNumbers里,行号右对齐和居中对齐貌似有问题

问题代码:

            switch (mLineNumberAlign) {
                case LEFT:
                    canvas.drawText(Integer.toString(i + 1), offsetX, y, mPaintOther);
                    break;
                case RIGHT:
                    canvas.drawText(Integer.toString(i + 1), offsetX + width, y, mPaintOther);
                    break;
                case CENTER:
                    canvas.drawText(Integer.toString(i + 1), offsetX + width / 2f, y, mPaintOther);
            }

应该可以这样解决(把行号分割线的边距也计算进去):

            String lineNumber = Integer.toString(i + 1);
            switch (mLineNumberAlign) {
                case LEFT:
                    canvas.drawText(lineNumber, offsetX, y, mPaintOther);
                    break;
                case RIGHT:
                    canvas.drawText(lineNumber, offsetX + width + mDividerMargin, y, mPaintOther);
                    break;
                case CENTER:
                    canvas.drawText(lineNumber, offsetX + (width + mDividerMargin) / 2f, y, mPaintOther);
            }

BTW:下面这两个计算行号宽度的凡是也许是等价的吧?都是以最大行号的宽度作为行号栏的宽。

    private float measureLineNumber() {
        int count = 0;
        int lineCount = getLineCount();
        while (lineCount > 0) {
            count++;
            lineCount /= 10;
        }
        float single = mPaintOther.measureText("0");
        return single * count * 1.01f;
    }
    private float measureLineNumber() {
        return mPaintOther.measureText(String.valueOf(getLineCount()));
    }

Bug when paste a text from the keyboard.

Hi,
i found a bug when i paste a text using my keyboard.
when i type something immediately after pasting a text using the paste option from the keyboard, it duplicate the text that has been pasted. but if i move the cursor to different position and then move it back, it works fine.
can you take a look at it please.
see the video below.
Thanks.

Screen_Recording_20210427-140451_Sketchware.Pro.mp4

Last typed word becomes invisible on typing a space, comma or dot ( . ).

I added the repo in my project as written in Readme. I had to override the chars() and codePoints() method in com.rose.editor.common.Content class (I had to override it because I got a error saying that I should implement the inherited abstract methods).

All things work fine except when I type a space, comma or a dot ( . )

I'm using AIDE to compile and run the project.

Any help or guidance is appreciated.

Merge some drawing processes

Also a requirement to merge some rendering processes into drawing text, such as cursor and its handle , and text background to speed up.
Separating these out can cause drawing to have a worse performance.
Draw text without spans can be merge into draw text with spans. And drawTextDirect() does not highlight selected text. This merge can solve it.

Originally posted by @Rosemoe in #15 (comment)

Current line background does not match text position

Current line background and line number does not match text position.
Recently it has been tested out on Huawei P6.
This is caused by the font used to draw line number and the font used to draw text have a different line height.

XML Analyzer/Language

It'd be cool to have a module for XML language too. We can't implement it using the simple way since XML needs tokenizing and analyzing for syntax highlighting, so the simple way is too limited..

[Bug] Crash on next search

Logcat:
Process: com.rose.editor.android, PID: 22360 java.lang.StringIndexOutOfBoundsException: String index out of range: -1 at io.github.rosemoe.editor.text.ContentLine.checkIndex(ContentLine.java:79) at io.github.rosemoe.editor.text.ContentLine.charAt(ContentLine.java:302) at android.text.TextUtils.indexOf(TextUtils.java:205) at android.text.TextUtils.indexOf(TextUtils.java:171) at android.text.TextUtils.indexOf(TextUtils.java:286) at android.text.TextUtils.indexOf(TextUtils.java:274) at io.github.rosemoe.editor.text.ContentLine.indexOf(ContentLine.java:241) at io.github.rosemoe.editor.widget.EditorSearcher.gotoNext(EditorSearcher.java:119) at io.github.rosemoe.editor.widget.EditorSearcher.gotoNext(EditorSearcher.java:109) at com.rose.editor.android.MainActivity.gotoNext(MainActivity.java:279) at com.rose.editor.android.MainActivity.onClick(MainActivity.java:316) at android.view.View.performClick(View.java:7870) at android.widget.TextView.performClick(TextView.java:14970) at android.view.View.performClickInternal(View.java:7839) at android.view.View.access$3600(View.java:886) at android.view.View$PerformClick.run(View.java:29363) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:237) at android.app.ActivityThread.main(ActivityThread.java:7948) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)
It is last source from dev branch. I am planning update handle to adroid edittext style, add cursor blinking and more)).

[Bug] Crashing when printing text

Crashing when printing text
java.lang.IndexOutOfBoundsException: Index: 4, Size: 0 at java.util.ArrayList.get(ArrayList.java:437) at io.github.rosemoe.editor.widget.CodeEditor.drawRows(CodeEditor.java:992) at io.github.rosemoe.editor.widget.CodeEditor.drawView(CodeEditor.java:838) at io.github.rosemoe.editor.widget.CodeEditor.onDraw(CodeEditor.java:3263) at android.view.View.draw(View.java:23191) at android.view.View.updateDisplayListIfDirty(View.java:22066) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:5214) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:5186) at android.view.View.updateDisplayListIfDirty(View.java:22021) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:5214) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:5186) at android.view.View.updateDisplayListIfDirty(View.java:22021) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:5214) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:5186) at android.view.View.updateDisplayListIfDirty(View.java:22021) at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:5214) at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:5186) at android.view.View.updateDisplayListIfDirty(View.java:22021) at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:588) at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:594) at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:667) at android.view.ViewRootImpl.draw(ViewRootImpl.java:4267) at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:4051) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3324) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2204) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9003) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:996) at android.view.Choreographer.doCallbacks(Choreographer.java:794) at android.view.Choreographer.doFrame(Choreographer.java:729) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:981) at android.os.Handler.handleCallback(Handler.java:883) at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:237) at android.app.ActivityThread.main(ActivityThread.java:7948) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1075)

Unable to highlight code using lexer

I'm implementing own CodeAnalyzer for Java Language (can't use existing one due to some reasons).

Here is the analyze () method :

			CodePointCharStream stream = CharStreams.fromReader(new StringReader(content.toString()));
			JavaLexer lexer = new JavaLexer(stream);
			Token token = null;
			boolean first = true;
			while(delegate.shouldAnalyze())
			{
				token = lexer.nextToken();
				if(token == null)
					break;
				if(token.getType() == JavaLexer.EOF)
					break;
				switch(token.getType())
				{
					case JavaLexer.WS :
						if(first)
							colors.addNormalIfNull();
						break;
					case JavaLexer.ABSTRACT:
					case JavaLexer.ASSERT:
					case JavaLexer.BREAK:
					case JavaLexer.CASE:
					case JavaLexer.CATCH:
					case JavaLexer.CLASS:
					case JavaLexer.CONST:
					case JavaLexer.CONTINUE:
					case JavaLexer.DEFAULT:
					case JavaLexer.DO:
					case JavaLexer.ELSE:
					case JavaLexer.ENUM:
					case JavaLexer.EXTENDS:
					case JavaLexer.FINAL:
					case JavaLexer.FINALLY:
					case JavaLexer.FOR:
					case JavaLexer.IF:
					case JavaLexer.GOTO:
					case JavaLexer.IMPLEMENTS:
					case JavaLexer.IMPORT:
					case JavaLexer.INSTANCEOF:
					case JavaLexer.INTERFACE:
					case JavaLexer.NATIVE:
					case JavaLexer.NEW:
					case JavaLexer.PACKAGE:
					case JavaLexer.PRIVATE:
					case JavaLexer.PROTECTED:
					case JavaLexer.PUBLIC:
					case JavaLexer.RETURN:
					case JavaLexer.STATIC:
					case JavaLexer.STRICTFP:
					case JavaLexer.SUPER:
					case JavaLexer.SWITCH:
					case JavaLexer.SYNCHRONIZED:
					case JavaLexer.THIS:
					case JavaLexer.THROW:
					case JavaLexer.THROWS:
					case JavaLexer.TRANSIENT:
					case JavaLexer.TRY:
					case JavaLexer.VOID:
					case JavaLexer.VOLATILE:
					case JavaLexer.WHILE:
						colors.addIfNeeded(token.getLine(), token.getCharPositionInLine(), EditorColorScheme.KEYWORD);
						break;
				}
				
				first = false;
			}

But nothing gets highlighted. If I forcibly add colors using color.add(), whole line is being highlighted.

Any suggestions?

Introduce font cache

After observing MT Manager's editor, I found his editor is much quicker than me.
This probably because it has some cache to measure text quickly.
Knowing this, I tested the speed of two ways to measure text. One with cache while another call native method directly.
When measuring a series of long text for several times, cached one is obvious quicker.
As the following images shows.
Screenshot_2020-08-18-15-22-59-923
Screenshot_2020-08-18-15-22-41-864
It is also faster in a single go:
Screenshot_2020-08-18-15-25-24-101
And their results are the same.
So you may use font caches to equip the editor.

Emoji测量不准和不识别\ud83e开头的Emoji

FontCache.java 中的isEmoji方法需要识别0xd83e,measureChar方法测量 一半的Emoji接一个Emoji会测量错误。应该改成
`/*
* 测量文本 0xd83c 0xd83c 0xdd51
* 0 1 2
*/
public float measureText(char[] chars, int start, int end, Paint p){
float width = 0f;
for( int i = start; i < end; i++ ){
char ch = chars [i];
if( isEmoji(ch) && i + 1 < end ){
buffer [0] = ch;
buffer [1] = chars [++i];

			if( i + 1 < end ){
				buffer [2] = chars [++i];
				if( !isEmoji(buffer [1]) || isEmoji(buffer [2]) ){
					//当第2个字符不是Emoji或第3字符是Emoji时,只测量两个字符
					i--;
					width += p.measureText(buffer, 0, 2);
				}
				else{
					width += p.measureText(buffer, 0, 3);
				}
			}
			else{
				width += p.measureText(buffer, 0, 2);
			}
		}
		else{
			width += measureChar(ch, p);
		}
	}
	return width;
}`

setHorizontalScrollBarEnabled(false)及setVerticalScrollBarEnabled(true)设置没效果,无法禁用滚动条

查阅代码,目测是就没用到isVerticalScrollBarEnabled()isHorizontalScrollBarEnabled(),需要修改drawScrollBars如下:

    private void drawScrollBars(Canvas canvas) {
        if (!mEventHandler.shouldDrawScrollBar()) {
            return;
        }
        if (isVerticalScrollBarEnabled()) {
            mVerticalScrollBar.setEmpty();
            if (getScrollMaxY() > getHeight() / 2) {
                drawScrollBarTrackVertical(canvas);
            }
            if (getScrollMaxY() > getHeight() / 2) {
                drawScrollBarVertical(canvas);
            }
        }
        if (isHorizontalScrollBarEnabled()) {
            mHorizontalScrollBar.setEmpty();
            if (getScrollMaxX() > getWidth() * 3 / 4) {
                drawScrollBarTrackHorizontal(canvas);
            }
            if (getScrollMaxX() > getWidth() * 3 / 4) {
                drawScrollBarHorizontal(canvas);
            }
        }
    }

Refactor and add plugin system

This includes the following tasks:

  • Reorganize code structure
  • Extract interfaces for text container due to future updates
  • Add plugin system
  • Make code more neat
  • Language Injection

Use incremental lexer to make highlight faster

Usually, a user types text but color for most regions of text is not going to change, unless the user is currently typing a comment.
So run lexer incrementally can make highlight faster than before and improve user experience greatly.
It is also easy to make a lexer made by JFlex to run incrementally.

custom code completion

Please add a custom code completion from a list.

also, all words between spaces will be appended to code completion as an identifier, can you please add option to disable this?

thank you.

AutoCompleteWindow isn't shown until EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD is specified in onCreateInputConnection.

AutoCompleteWindow isn't shown until EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD is specified in onCreateInputConnection.

If EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD along with EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS is specified as input type, long pressing the backspace key in Soft Keyboard doesn't work. It acts as backspace was clicked only once.

This is a video showing what's happens when I use EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD. Notice the long click on delete key. It doesn't work.

This video shows what happen when I remove the EditorInfo.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD flag. Due to text suggestions provided by keyboard, AutoCompleteWindow isn't shown. AutoCompleteWindow is only shown when I click the suggestion in keyboard.

uncaughtException java.lang.AbstractMethodError when install the signed APK of sample app

I'm getting the following exception when install the signed APK of the sample app.

    java.lang.AbstractMethodError: abstract method "io.github.rosemoe.editor.widget.SymbolPairMatch io.github.rosemoe.editor.interfaces.EditorLanguage.getSymbolPairs()"
        at io.github.rosemoe.editor.widget.CodeEditor.setEditorLanguage(CodeEditor.java:635)
        at io.github.rosemoe.editor.app.MainActivity.onCreate(MainActivity.java:95)
        at android.app.Activity.performCreate(Activity.java:6942)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2880)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2988)
        at android.app.ActivityThread.-wrap14(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1631)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6682)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

[Feature] Add Wordwrap

Hello, the good idea was to create such a editor. But it does not have enough, the wordwrap content

Crash while selecting text in some situations

Crash log:
java.lang.IllegalArgumentException: start > end
at com.rose.editor.android.RoseEditor.setSelectionRegion(RoseEditor.java:2334)
at com.rose.editor.android.EventHandler$SelectionHandle.applyPosition(EventHandler.java:558)
at com.rose.editor.android.EventHandler.onTouchEvent(EventHandler.java:251)
at com.rose.editor.android.RoseEditor.onTouchEvent(RoseEditor.java:2614)
at android.view.View.dispatchTouchEvent(View.java:11843)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2981)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2668)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2981)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2668)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2981)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2668)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2981)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2668)
at com.android.internal.policy.DecorView.superDispatchTouchEvent(DecorView.java:555)
at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1894)
at android.app.Activity.dispatchTouchEvent(Activity.java:3508)
at com.android.internal.policy.DecorView.dispatchTouchEvent(DecorView.java:508)
at android.view.View.dispatchPointerEvent(View.java:12082)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:5463)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:5247)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4737)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4790)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4756)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:4887)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4764)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:4944)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4737)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:4790)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:4756)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:4764)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:4737)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:7363)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:7337)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:7295)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:7514)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:193)
at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents(Native Method)
at android.view.InputEventReceiver.consumeBatchedInputEvents(InputEventReceiver.java:182)
at android.view.ViewRootImpl.doConsumeBatchedInput(ViewRootImpl.java:7445)
at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run(ViewRootImpl.java:7550)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1041)
at android.view.Choreographer.doCallbacks(Choreographer.java:847)
at android.view.Choreographer.doFrame(Choreographer.java:768)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1027)
at android.os.Handler.handleCallback(Handler.java:809)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7555)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)

Optimize concurrent modification when copying text in analyze thread

Iterator should be replaced with for loop with list size.
Log:
java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.next(ArrayList.java:860)
at com.rose.editor.common.Content.toStringBuilder(Content.java:505)
at com.rose.editor.common.TextColorProvider$AnalyzeThread.run(TextColorProvider.java:135)

Enabling Samsung Keyboard's suggestions option makes the Editor crash.

when i open the editor for the first time, everything is fine,
but once i click on the editor to open the keyboard, it suddenly becomes red. that red color is being used in color.xml in my app as ColorControlHighlight.
can you fix it please, it's so annoying.

thanks.

Screen_Recording_20210331-192022.mp4

[Bug] Doesn't automatically scroll when editing text

A bug was found when you type text, then when adding new lines, it does not automatically spliced ​​down, for the visibility of the input, also if there is a long text, it is also strange to spliced ​​text to the left

编辑器主题、语法高亮配色方案改进建议

我在编辑器主题、语法高亮配色方案方面进行了大量重写,由于重构太大了不好合并进入你的分支,贴出部分代码如下供参考:

    public void setThemeScheme(ThemeScheme themeScheme) {
        if (themeScheme == null) {
            return;
        }
        this.themeScheme = themeScheme;
        notifyThemeChanged();
        invalidate();
    }

    public void setThemeScheme(@ThemeType int themeType) {
        switch (themeType) {
            case ThemeType.DARCULA:
                setThemeScheme(new Darcula());
                break;
            case ThemeType.VS2019:
                setThemeScheme(new VS2019());
                break;
            case ThemeType.GITHUB:
                setThemeScheme(new Github());
                break;
            default:
                setThemeScheme(new Default());
                break;
        }
    }

    public void addThemeWather(ThemeWatcher watcher) {
        themeWatchers.add(watcher);
    }

    public void removeThemeWather(ThemeWatcher watcher) {
        themeWatchers.remove(watcher);
    }

    protected void notifyThemeChanged() {
        for (ThemeWatcher watcher : themeWatchers) {
            watcher.onThemeChanged(themeScheme);
        }
    }
/**
 * `Darcula` style, color picked from Android Studio
 *
 * @author gzu-liyujiang ([email protected])
 */
@Retention(RetentionPolicy.SOURCE)
public @interface ThemeType {
    int DEFAULT = 0;
    int DARCULA = 1;
    int VS2019 = 2;
    int GITHUB = 3;
}
/**
 * Theme scheme for all UI
 *
 * @author gzu-liyujiang ([email protected])
 */
public interface ThemeScheme {

    @ColorInt
    int getAnnotationColor();

    @ColorInt
    int getFunctionNameColor();

    @ColorInt
    int getIdentifierNameColor();

    @ColorInt
    int getIdentifierVarColor();

    @ColorInt
    int getLiteralColor();

    @ColorInt
    int getOperatorColor();

    @ColorInt
    int getCommentColor();

    @ColorInt
    int getKeywordColor();

    @ColorInt
    int getPrimaryBackgroundColor();

    @ColorInt
    int getPrimaryForegroundColor();

    @ColorInt
    int getSecondaryBackgroundColor();

    @ColorInt
    int getSecondaryForegroundColor();

    @ColorInt
    int getGutterBackgroundColor();

    @ColorInt
    int getGutterForegroundColor();

    @ColorInt
    int getScrollBarThumbTrackColor();

    @ColorInt
    int getScrollBarThumbNormalColor();

    @ColorInt
    int getScrollBarThumbPressedColor();

    @ColorInt
    int getSelectedTextBackgroundColor();

    @ColorInt
    int getMatchedTextBackgroundColor();

    @ColorInt
    int getCurrentLineBackgroundColor();

    @ColorInt
    int getCursorColor();

    @ColorInt
    int getNonPrintableColor();
    
    @ColorInt
    int getCodeBlockLineColor();

    @ColorInt
    int getUnderlineColor();

    boolean isDark();

}
/**
 * Default style. Refer default color scheme from AIDE, Notepad++ etc.
 *
 * @author gzu-liyujiang ([email protected])
 */
public class Default implements ThemeScheme {

    @Override
    public int getAnnotationColor() {
        return 0xFF03A9F4;
    }

    @Override
    public int getFunctionNameColor() {
        return 0xff333333;
    }

    @Override
    public int getIdentifierNameColor() {
        return 0xFF333333;
    }

    @Override
    public int getIdentifierVarColor() {
        return 0xff333333;
    }

    @Override
    public int getLiteralColor() {
        return 0xFF008080;
    }

    @Override
    public int getOperatorColor() {
        return 0xFF0066D6;
    }

    @Override
    public int getCommentColor() {
        return 0xffa8a8a8;
    }

    @Override
    public int getKeywordColor() {
        return 0xFF2196F3;
    }

    @Override
    public int getPrimaryBackgroundColor() {
        return 0xffffffff;
    }

    @Override
    public int getPrimaryForegroundColor() {
        return 0xFF333333;
    }

    @Override
    public int getSecondaryBackgroundColor() {
        return 0xff3c3f41;
    }

    @Override
    public int getSecondaryForegroundColor() {
        return 0xFF000000;
    }

    @Override
    public int getGutterBackgroundColor() {
        return 0xfff0f0f0;
    }

    @Override
    public int getGutterForegroundColor() {
        return 0xFF808080;
    }

    @Override
    public int getScrollBarThumbTrackColor() {
        return 0;
    }

    @Override
    public int getScrollBarThumbNormalColor() {
        return 0xffd8d8d8;
    }

    @Override
    public int getScrollBarThumbPressedColor() {
        return 0xFF27292A;
    }

    @Override
    public int getSelectedTextBackgroundColor() {
        return 0xFF9E9E9E;
    }

    @Override
    public int getMatchedTextBackgroundColor() {
        return 0xffffff00;
    }

    @Override
    public int getCurrentLineBackgroundColor() {
        return 0x10000000;
    }

    @Override
    public int getCursorColor() {
        return 0xFF03EBEB;
    }

    @Override
    public int getNonPrintableColor() {
        return 0xffdddddd;
    }
 
    @Override
    public int getCodeBlockLineColor() {
        return 0xff808080;
    }

    @Override
    public int getUnderlineColor() {
        return 0xff0000;
    }

    @Override
    public boolean isDark() {
        return false;
    }

}

image

/**
 * `Darcula` style, color picked from Android Studio
 *
 * @author gzu-liyujiang ([email protected])
 */
public class Darcula implements ThemeScheme {

    @Override
    public int getAnnotationColor() {
        return 0xffbbb529;
    }

    @Override
    public int getFunctionNameColor() {
        return 0xffffffff;
    }

    @Override
    public int getIdentifierNameColor() {
        return 0xffffffff;
    }

    @Override
    public int getIdentifierVarColor() {
        return 0xff9876aa;
    }

    @Override
    public int getLiteralColor() {
        return 0xff6a8759;
    }

    @Override
    public int getOperatorColor() {
        return 0xffffffff;
    }

    @Override
    public int getCommentColor() {
        return 0xff808080;
    }

    @Override
    public int getKeywordColor() {
        return 0xffcc7832;
    }

    @Override
    public int getPrimaryBackgroundColor() {
        return 0xff2b2b2b;
    }

    @Override
    public int getPrimaryForegroundColor() {
        return 0xffffffff;
    }

    @Override
    public int getSecondaryBackgroundColor() {
        return 0xff3c3f41;
    }

    @Override
    public int getSecondaryForegroundColor() {
        return 0xff787878;
    }

    @Override
    public int getGutterBackgroundColor() {
        return 0xff313335;
    }

    @Override
    public int getGutterForegroundColor() {
        return 0xff606366;
    }

    @Override
    public int getScrollBarThumbTrackColor() {
        return 0;
    }

    @Override
    public int getScrollBarThumbNormalColor() {
        return 0xffa6a6a6;
    }

    @Override
    public int getScrollBarThumbPressedColor() {
        return 0xff565656;
    }

    @Override
    public int getSelectedTextBackgroundColor() {
        return 0xff3676b8;
    }

    @Override
    public int getMatchedTextBackgroundColor() {
        return 0xff32593d;
    }

    @Override
    public int getCurrentLineBackgroundColor() {
        return 0xff323232;
    }

    @Override
    public int getCursorColor() {
        return 0xffffffff;
    }
    
    @Override
    public int getNonPrintableColor() {
        return 0xff404040;
    }

    @Override
    public int getCodeBlockLineColor() {
        return 0xff575757;
    }

    @Override
    public int getUnderlineColor() {
        return 0xffff0000;
    }

    @Override
    public boolean isDark() {
        return true;
    }

}

image

/**
 * `Github` style, color picked from Github website
 *
 * @author gzu-liyujiang ([email protected])
 */
public class Github implements ThemeScheme {

    @Override
    public int getAnnotationColor() {
        return 0xffde3a49;
    }

    @Override
    public int getFunctionNameColor() {
        return 0xff6f42c1;
    }

    @Override
    public int getIdentifierNameColor() {
        return 0xff24292e;
    }

    @Override
    public int getIdentifierVarColor() {
        return 0xff24292e;
    }

    @Override
    public int getLiteralColor() {
        return 0xff032f62;
    }

    @Override
    public int getOperatorColor() {
        return 0xffde3a49;
    }

    @Override
    public int getCommentColor() {
        return 0xff6a737d;
    }

    @Override
    public int getKeywordColor() {
        return 0xffde3a49;
    }

    @Override
    public int getPrimaryBackgroundColor() {
        return 0xffffffff;
    }

    @Override
    public int getPrimaryForegroundColor() {
        return 0xff24292e;
    }

    @Override
    public int getSecondaryBackgroundColor() {
        return 0xfff1f1f1;
    }

    @Override
    public int getSecondaryForegroundColor() {
        return 0xff000000;
    }

    @Override
    public int getGutterBackgroundColor() {
        return 0xffffffff;
    }

    @Override
    public int getGutterForegroundColor() {
        return 0xffb1c0c1;
    }

    @Override
    public int getScrollBarThumbTrackColor() {
        return 0;
    }

    @Override
    public int getScrollBarThumbNormalColor() {
        return 0xffd8d8d8;
    }

    @Override
    public int getScrollBarThumbPressedColor() {
        return 0xFF27292A;
    }

    @Override
    public int getSelectedTextBackgroundColor() {
        return 0xFF9E9E9E;
    }

    @Override
    public int getMatchedTextBackgroundColor() {
        return 0xffffff00;
    }

    @Override
    public int getCurrentLineBackgroundColor() {
        return 0x10000000;
    }

    @Override
    public int getCursorColor() {
        return 0xFFC7EDCC;
    }

    @Override
    public int getNonPrintableColor() {
        return 0xffdddddd;
    }

    @Override
    public int getCodeBlockLineColor() {
        return 0xff808080;
    }

    @Override
    public int getUnderlineColor() {
        return 0xffff0000;
    }

    @Override
    public boolean isDark() {
        return false;
    }

}

image

/**
 * `VS2019` style, color picked from Visual Studio 2019
 *
 * @author gzu-liyujiang ([email protected])
 */
public class VS2019 implements ThemeScheme {

    @Override
    public int getAnnotationColor() {
        return 0xff4ec9b0;
    }

    @Override
    public int getFunctionNameColor() {
        return 0xffdcdcdc;
    }

    @Override
    public int getIdentifierNameColor() {
        return 0xffdcdcdc;
    }

    @Override
    public int getIdentifierVarColor() {
        return 0xffdcdcdc;
    }

    @Override
    public int getLiteralColor() {
        return 0xffd69d85;
    }

    @Override
    public int getOperatorColor() {
        return 0xffb4b4b4;
    }

    @Override
    public int getCommentColor() {
        return 0xff608b4e;
    }

    @Override
    public int getKeywordColor() {
        return 0xff569cd6;
    }

    @Override
    public int getPrimaryBackgroundColor() {
        return 0xff1e1e1e;
    }

    @Override
    public int getPrimaryForegroundColor() {
        return 0xffdcdcdc;
    }

    @Override
    public int getSecondaryBackgroundColor() {
        return 0xff2d2d30;
    }

    @Override
    public int getSecondaryForegroundColor() {
        return 0xfff1f1f1;
    }

    @Override
    public int getGutterBackgroundColor() {
        return 0xff1e1e1e;
    }

    @Override
    public int getGutterForegroundColor() {
        return 0xff2b9eaf;
    }

    @Override
    public int getScrollBarThumbTrackColor() {
        return 0;
    }

    @Override
    public int getScrollBarThumbNormalColor() {
        return 0xff3e3e42;
    }

    @Override
    public int getScrollBarThumbPressedColor() {
        return 0xff9e9e9e;
    }

    @Override
    public int getSelectedTextBackgroundColor() {
        return 0xff3676b8;
    }

    @Override
    public int getMatchedTextBackgroundColor() {
        return 0xff653306;
    }

    @Override
    public int getCurrentLineBackgroundColor() {
        return 0xff464646;
    }

    @Override
    public int getCursorColor() {
        return 0xffffffff;
    }

    @Override
    public int getNonPrintableColor() {
        return 0xff343434;
    }

    @Override
    public int getCodeBlockLineColor() {
        return 0xff565656;
    }

    @Override
    public int getUnderlineColor() {
        return 0xffff0000;
    }

    @Override
    public boolean isDark() {
        return true;
    }

}

image

/**
 * Theme changed watcher
 *
 * @author gzu-liyujiang ([email protected])
 */
public interface ThemeWatcher {

    void onThemeChanged(ThemeScheme themeScheme);

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.