mirror of
https://github.com/thunderbird/thunderbird-android.git
synced 2024-09-20 12:12:15 +02:00
Wrap pasted URIs in angle brackets
This commit is contained in:
parent
e5e2a9bafb
commit
12a7b31046
@ -109,6 +109,7 @@ import com.fsck.k9.search.LocalSearch;
|
||||
import com.fsck.k9.ui.R;
|
||||
import com.fsck.k9.ui.base.K9Activity;
|
||||
import com.fsck.k9.ui.base.ThemeManager;
|
||||
import com.fsck.k9.ui.compose.WrapUriTextWatcher;
|
||||
import com.fsck.k9.ui.compose.QuotedMessageMvpView;
|
||||
import com.fsck.k9.ui.compose.QuotedMessagePresenter;
|
||||
import com.fsck.k9.ui.helper.SizeFormatter;
|
||||
@ -360,10 +361,12 @@ public class MessageCompose extends K9Activity implements OnClickListener,
|
||||
replyToView.addTextChangedListener(draftNeedsChangingTextWatcher);
|
||||
recipientMvpView.addTextChangedListener(draftNeedsChangingTextWatcher);
|
||||
quotedMessageMvpView.addTextChangedListener(draftNeedsChangingTextWatcher);
|
||||
quotedMessageMvpView.addTextChangedListener(new WrapUriTextWatcher());
|
||||
|
||||
subjectView.addTextChangedListener(draftNeedsChangingTextWatcher);
|
||||
|
||||
messageContentView.addTextChangedListener(draftNeedsChangingTextWatcher);
|
||||
messageContentView.addTextChangedListener(new WrapUriTextWatcher());
|
||||
|
||||
/*
|
||||
* We set this to invisible by default. Other methods will turn it back on if it's
|
||||
|
@ -0,0 +1,41 @@
|
||||
package com.fsck.k9.ui.compose
|
||||
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import com.fsck.k9.message.html.UriMatcher
|
||||
|
||||
private const val NO_INDEX = -1
|
||||
private const val MINIMUM_URI_LENGTH = 2 // scheme name + colon
|
||||
|
||||
/**
|
||||
* Wraps inserted URIs in angle brackets.
|
||||
*/
|
||||
class WrapUriTextWatcher : TextWatcher {
|
||||
private var insertedStartIndex = NO_INDEX
|
||||
private var insertedEndIndex = NO_INDEX
|
||||
|
||||
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) = Unit
|
||||
|
||||
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
|
||||
if (s == null || count < MINIMUM_URI_LENGTH) {
|
||||
insertedStartIndex = NO_INDEX
|
||||
} else {
|
||||
insertedStartIndex = start
|
||||
insertedEndIndex = start + count
|
||||
}
|
||||
}
|
||||
|
||||
override fun afterTextChanged(s: Editable?) {
|
||||
// Changing s below will lead to this TextWatcher being invoked again. Keep necessary state local.
|
||||
val insertedStartIndex = insertedStartIndex
|
||||
val insertedEndIndex = insertedEndIndex
|
||||
|
||||
if (s != null && insertedStartIndex != NO_INDEX) {
|
||||
val insertedText = s.subSequence(insertedStartIndex, insertedEndIndex)
|
||||
if (UriMatcher.isValidUri(insertedText)) {
|
||||
s.insert(insertedEndIndex, ">")
|
||||
s.insert(insertedStartIndex, "<")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user