Skip to content

Commit

Permalink
Pluralization fixes when only 1 tab was selected
Browse files Browse the repository at this point in the history
Closes #87
  • Loading branch information
mastef committed Jun 22, 2020
1 parent b9ef0eb commit 37ee011
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/TabManager.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class TabManager extends React.Component {
disabled={true}
className="tabtitle"
ref="topbox"
placeholder={tabCount + " tabs in " + this.state.windows.length + " windows"}
placeholder={maybePluralize(tabCount, 'tab') + " in " + this.state.windows.length + " windows"}
value={this.state.topText}
/>
<input type="text" disabled={true} className="taburl" ref="topboxurl" placeholder={this.getTip()} value={this.state.bottomText} />
Expand All @@ -428,7 +428,7 @@ class TabManager extends React.Component {
className="icon windowaction trash"
title={
Object.keys(this.state.selection).length > 0
? "Close selected tabs\nWill close " + Object.keys(this.state.selection).length + " tabs"
? "Close selected tabs\nWill close " + maybePluralize(Object.keys(this.state.selection).length, 'tab')
: "Close current Tab"
}
onClick={this.deleteTabs}
Expand All @@ -438,7 +438,7 @@ class TabManager extends React.Component {
className="icon windowaction discard"
title={
Object.keys(this.state.selection).length > 0
? "Discard selected tabs\nWill discard " + Object.keys(this.state.selection).length + " tabs - freeing memory"
? "Discard selected tabs\nWill discard " + maybePluralize(Object.keys(this.state.selection).length, 'tab') + " - freeing memory"
: "Select tabs to discard them and free memory"
}
style={
Expand All @@ -453,7 +453,7 @@ class TabManager extends React.Component {
className="icon windowaction pin"
title={
Object.keys(this.state.selection).length > 0
? "Pin selected tabs\nWill pin " + Object.keys(this.state.selection).length + " tabs"
? "Pin selected tabs\nWill pin " + maybePluralize(Object.keys(this.state.selection).length, 'tab')
: "Pin current Tab"
}
onClick={this.pinTabs}
Expand All @@ -467,8 +467,7 @@ class TabManager extends React.Component {
(this.state.searchLen > 0
? "\n" +
(this.state.filterTabs ? "Will reveal " : "Will hide ") +
(Object.keys(this.state.tabsbyid).length - Object.keys(this.state.selection).length) +
" tabs"
maybePluralize((Object.keys(this.state.tabsbyid).length - Object.keys(this.state.selection).length), 'tab')
: "")
}
onClick={this.toggleFilterMismatchedTabs}
Expand All @@ -478,7 +477,7 @@ class TabManager extends React.Component {
className="icon windowaction new"
title={
Object.keys(this.state.selection).length > 0
? "Move tabs to new window\nWill move " + Object.keys(this.state.selection).length + " selected tabs to it"
? "Move tabs to new window\nWill move " + maybePluralize(Object.keys(this.state.selection).length, 'selected tab') + " to it"
: "Open new empty window"
}
onClick={this.addWindow}
Expand Down Expand Up @@ -1713,3 +1712,6 @@ function debounce(func, wait, immediate) {
if (callNow) func.apply(context, args);
};
}

const maybePluralize = (count, noun, suffix = 's') =>
`${count} ${noun}${count !== 1 ? suffix : ''}`;

0 comments on commit 37ee011

Please sign in to comment.