Skip to content

developer-krushna/MH-TextEditor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

86 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“ MH-TextEditor

A powerful, lightweight text editor for Android with syntax highlighting, smooth editing experience, and professional code editing features.

⚠️ Note: This editor may not fully support some Android keyboards yet.
Compatibility improvements are under active development as part of ongoing research.


πŸ“± Screenshots

Screenshot 1 Screenshot 2
Screenshot 3 Screenshot 4
------------------------------------------ ------------------------------------------
Screenshot 5 Screenshot 6

✨ Features

🧩 Core Editing

  • Smooth Text Editing β€” Fast and responsive typing experience
  • Syntax Highlighting β€” Support for multiple programming languages (Java, XML, JSON, etc.)
  • Line Numbers β€” Clean, right-aligned line numbers with proper margins
  • Customizable Text Size β€” Pinch-to-zoom and manual text size adjustment
  • Multiple Font Support β€” Custom typeface support for better readability

βœ‚οΈ Advanced Text Manipulation

  • Smart Selection β€” Word selection, line selection, and text range selection
  • Copy / Cut / Paste β€” Full clipboard support with system integration
  • Find & Replace β€” Regex-powered search and replace functionality
  • Undo / Redo β€” Unlimited undo/redo operations with gap buffer implementation
  • Auto-Indent β€” Smart indentation preservation on new lines

βš™οΈ Professional Tools

  • Magnifier β€” Built-in magnifier for precise cursor positioning
  • Selection Handles β€” Visual drag handles for text selection
  • Floating Clipboard Panel β€” Context-aware clipboard actions
  • Keyboard Support β€” Full hardware keyboard support with meta keys
  • Input Method Support β€” Optimized for various soft keyboards

πŸš€ Performance & UX

  • Gap Buffer Implementation β€” Efficient text storage for large files
  • Smooth Scrolling β€” Physics-based scrolling with fling gestures
  • Cursor Blink β€” Visual cursor indication with customizable blink rate
  • Touch Gestures β€” Double-tap, long-press, and scroll gestures
  • Auto-complete β€” Intelligent word completion and suggestions

πŸš€ Getting Started

Basic Usage

<!-- In your layout XML -->
<modder.hub.editor.EditView
    android:id="@+id/editView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
	android:layout_marginTop="0dp"
    android:layout_marginStart="0dp"
    android:paddingTop="0dp"
    android:paddingStart="0dp" 
    android:focusable="true"
    android:focusableInTouchMode="true"/>
// In your Activity
EditView editView = findViewById(R.id.editView);
editView.setText("Your code here");
editView.setSyntaxLanguageFileName("java.json");

Advanced Configuration

// Set text size
editView.setTextSize(16); // in pixels

// Enable features
editView.setMagnifierEnabled(true);
editView.setAutoIndentEnabled(true);

// Set typeface
Typeface typeface = Typeface.MONOSPACE;
editView.setTypeface(typeface);

// Set listeners
editView.setOnTextChangedListener(new OnTextChangedListener() {
    @Override
    public void onTextChanged() {
        // Handle text changes
    }
});

πŸ› οΈ API Reference

Core Methods

Method Description
setText(String text) Set editor content
getText() Get current text
setTextSize(float size) Set text size in pixels
setTypeface(Typeface typeface) Set custom typeface
setSyntaxHighlightingEnabled(boolean enabled) Toggle syntax highlighting

Editing Operations

Method Description
undo() Undo last operation
redo() Redo last operation
copy() Copy selected text
cut() Cut selected text
paste() Paste from clipboard
selectAll() Select all text
clearSelection() Clear current selection

Navigation & Search

Method Description
gotoLine(int line) Navigate to specific line
find(String regex) Find text using regex
replaceFirst(String replacement) Replace first match
replaceAll(String replacement) Replace all matches

Configuration

Method Description
setEditedMode(boolean editMode) Enable/disable editing
setMagnifierEnabled(boolean enabled) Toggle magnifier
setAutoIndentEnabled(boolean enabled) Toggle auto-indent
setOnTextChangedListener(OnTextChangedListener listener) Text change callback

🎨 Customization

Theming

// Custom colors
editView.setBackgroundColor(Color.WHITE);
editView.setLineNumberBackground(Color.parseColor("#F8F8F8"));
editView.setLineNumberColor(Color.GRAY);

Syntax Highlighting

Add custom syntax definition files in JSON format to extend language support:

{
  "name": ["Java", ".java", ".jsp"],
  "comment": [
    { "startsWith": "//" },
    { "startsWith": "/*", "endsWith": "*/" }
  ],

  "rules": [
    // Single-line and multi-line comments
    { "type": "comment", "regex": "//.*" },
    { "type": "comment", "regex": "/\\*[\\s\\S]*?\\*/" },
      // Triple-quoted strings
    {
      "regex": "\"\"\"[\\s\\S]*?\"\"\"",
      "groupStyles": { "0": "string" }
    },

    // Quoted strings
    { "type": "string", "regex": "\"(?:\\\\.|[^\"])*\"" },
    { "type": "string", "regex": "'(?:\\\\.|[^'])'" }
  ]
}   

πŸ“ File Structure

app/
β”œβ”€β”€ editor/
β”‚   β”œβ”€β”€ EditView.java           # Main editor component
β”‚   β”œβ”€β”€ GapBuffer.java          # Efficient text storage
β”‚   β”œβ”€β”€ WordWrapLayout.java   # Word wrapping implementation(Not ready)
β”‚   β”œβ”€β”€ highlight/
β”‚   β”‚   └── SyntaxConfig.java   # Syntax highlighting engine
β”‚   └── component/
β”‚       └── ClipboardPanel.java # Clipboard context menu

πŸ”„ Integration with Other Components

With Activity

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.editor_menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_undo:
            editView.undo();
            return true;
        case R.id.menu_redo:
            editView.redo();
            return true;
        case R.id.menu_find:
            showFindDialog();
            return true;
    }
    return super.onOptionsItemSelected(item);
}

With File System

// Load file
String fullText = readFile(path.toString());
// Replace buffer wholesale (like setText, but async)
GapBuffer newBuffer = new GapBuffer(fullText);
editView.setBuffer(newBuffer);

// Save file
String content = editView.getText();
writeFile(filePath, content);

πŸ› Troubleshooting

Common Issues

  1. Keyboard not showing

    • Ensure setFocusable(true) and setFocusableInTouchMode(true) are called
    • Check input connection implementation
  2. Keyboard not supporting

    • As of my test I have seen some keyboards are not working for the editor causing unexpected issues..
    • So it's recommended to use Google Keyboard for testing now..
    • I will try to improve the KeyUp and down function
  3. Syntax highlighting not working

    • Verify syntax definition files are in assets
    • Check if highlighter is properly initialized
  4. Performance with large files

    • Use gap buffer optimization
    • Enable word wrap for better performance

Logging

Enable debug logging to troubleshoot issues:

Log.d("MH-TextEditor", "Current cursor: " + editView.getCaretPosition());

πŸ“„ License

Copyright (C) 2025 Krushna Chandra(@developer-krushna)

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

This program 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 General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

🀝 Contributing

We welcome contributions! Please feel free to submit pull requests, report bugs, or suggest new features.

Development Setup

  1. Fork the repository
  2. Clone your fork
  3. Create a feature branch
  4. Make your changes
  5. Submit a pull request

Code Style

  • Follow Android code style guidelines
  • Use meaningful variable names
  • Add comments for complex logic
  • Include JavaDoc for public methods

πŸ“ž Support

If you encounter any issues or have questions:

  1. Check the Issues page
  2. Create a new issue with detailed description
  3. Provide code samples and error logs

πŸ™ Acknowledgments

  • Inspired by modern code editors
  • Thanks to contributors and testers
  • Built with attention to performance and user experience

MH-TextEditor β€” Making code editing on Android better, one line at a time.

About

MH TextEditor is an optimized large text/code editor for Android

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages