Limit the number of characters for user completion and issue completioin (#2534)

This commit is contained in:
onukura
2020-09-07 03:55:11 +09:00
committed by GitHub
parent 8dbcbb5485
commit 0da781c33d
4 changed files with 13 additions and 10 deletions

View File

@@ -213,8 +213,10 @@ trait IndexControllerBase extends ControllerBase {
}
.map { t =>
Map(
"label" -> s"${avatar(t.userName, 16)}<b>@${StringUtil.escapeHtml(t.userName)}</b> ${StringUtil
.escapeHtml(t.fullName)}",
"label" -> s"${avatar(t.userName, 16)}<b>@${StringUtil.escapeHtml(
StringUtil.cutTail(t.userName, 25, "...")
)}</b> ${StringUtil
.escapeHtml(StringUtil.cutTail(t.fullName, 25, "..."))}",
"value" -> t.userName
)
}

View File

@@ -430,7 +430,8 @@ trait IssuesControllerBase extends ControllerBase {
Map(
"label" -> s"""${if (t.isPullRequest) "<i class='octicon octicon-git-pull-request'></i>"
else "<i class='octicon octicon-issue-opened'></i>"}<b> #${StringUtil
.escapeHtml(t.issueId.toString)} ${StringUtil.escapeHtml(t.title)}</b>""",
.escapeHtml(t.issueId.toString)} ${StringUtil
.escapeHtml(StringUtil.cutTail(t.title, 50, "..."))}</b>""",
"value" -> t.issueId.toString
)
}

View File

@@ -182,4 +182,11 @@ object StringUtil {
}
}
def cutTail(txt: String, limit: Int, suffix: String = ""): String = {
txt.length match {
case x if x > limit => txt.substring(0, limit).concat(suffix)
case _ => txt
}
}
}

View File

@@ -186,13 +186,6 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
def link(value: String, repository: RepositoryService.RepositoryInfo)(implicit context: Context): Html =
Html(decorateHtml(convertRefsLinks(value, repository), repository))
def cut(value: String, length: Int): String =
if (value.length > length) {
value.substring(0, length) + "..."
} else {
value
}
import scala.util.matching.Regex._
implicit class RegexReplaceString(private val s: String) extends AnyVal {
def replaceAll(pattern: String)(replacer: Match => String): String = {