9 Commits

Author SHA1 Message Date
Anthony Sottile
99b3371739 v0.0.24 2021-10-03 18:55:37 -04:00
Anthony Sottile
3c9c6173c3 Merge pull request #164 from AndrewLaneX/replace-errors
Handle errors when replacing
2021-10-03 15:53:22 -07:00
Andrew Lane
84015d3ac4 Handle errors when replacing 2021-10-03 23:45:29 +03:00
Anthony Sottile
d7ffdd1db8 Merge pull request #163 from asottile/pre-commit-ci-update-config
[pre-commit.ci] pre-commit autoupdate
2021-09-27 13:26:18 -07:00
pre-commit-ci[bot]
4e0c02eaa2 [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/asottile/pyupgrade: v2.26.0 → v2.28.0](https://github.com/asottile/pyupgrade/compare/v2.26.0...v2.28.0)
2021-09-27 20:16:08 +00:00
Anthony Sottile
79919ece2a Merge pull request #162 from asottile/pre-commit-ci-update-config
[pre-commit.ci] pre-commit autoupdate
2021-09-13 13:30:33 -07:00
pre-commit-ci[bot]
f0ad0e4977 [pre-commit.ci] pre-commit autoupdate
updates:
- [github.com/asottile/pyupgrade: v2.25.0 → v2.26.0](https://github.com/asottile/pyupgrade/compare/v2.25.0...v2.26.0)
2021-09-13 20:11:28 +00:00
Anthony Sottile
f18796b78d Merge pull request #161 from asottile/a-italic
A_ITALIC is not always present unlike what's documented
2021-09-12 06:47:05 -07:00
Anthony Sottile
1698533787 A_ITALIC is not always present unlike what's documented 2021-09-12 06:42:28 -07:00
5 changed files with 22 additions and 4 deletions

View File

@@ -30,7 +30,7 @@ repos:
- id: add-trailing-comma
args: [--py36-plus]
- repo: https://github.com/asottile/pyupgrade
rev: v2.25.0
rev: v2.28.0
hooks:
- id: pyupgrade
args: [--py37-plus]

View File

@@ -20,6 +20,8 @@ from babi.user_data import prefix_data
from babi.user_data import xdg_config
from babi.user_data import xdg_data
A_ITALIC = getattr(curses, 'A_ITALIC', 0x80000000) # not always present
class FileSyntax:
include_edge = False
@@ -47,7 +49,7 @@ class FileSyntax:
return (
curses.color_pair(pair) |
curses.A_BOLD * style.b |
curses.A_ITALIC * style.i |
A_ITALIC * style.i |
curses.A_UNDERLINE * style.u
)

View File

@@ -7,6 +7,7 @@ import hashlib
import os
import re
import signal
import sre_parse
import sys
from typing import Generator
from typing import NamedTuple
@@ -419,7 +420,12 @@ class Screen:
'replace with', history='replace', allow_empty=True,
)
if response is not PromptResult.CANCELLED:
self.file.replace(self, search_response, response)
try:
sre_parse.parse_template(response, search_response)
except re.error:
self.status.update('invalid replacement string')
else:
self.file.replace(self, search_response, response)
def command(self) -> EditResult | None:
response = self.prompt('', history='command')

View File

@@ -1,6 +1,6 @@
[metadata]
name = babi
version = 0.0.22
version = 0.0.24
description = a text editor
long_description = file: README.md
long_description_content_type = text/markdown

View File

@@ -22,6 +22,16 @@ def test_replace_invalid_regex(run):
h.await_text("invalid regex: '('")
def test_replace_invalid_replacement(run, ten_lines):
with run(str(ten_lines)) as h, and_exit(h):
h.press('^\\')
h.await_text('search (to replace):')
h.press_and_enter('line_0')
h.await_text('replace with:')
h.press_and_enter('\\')
h.await_text('invalid replacement string')
def test_replace_cancel_at_replace_string(run):
with run() as h, and_exit(h):
h.press('^\\')